Command Line interface (CLI)
124
votes
39answers
22k views
What useful things can one add to one's .bashrc? [closed]
Is there anything that you can't live without and will make my life SO much easier? Here are some that I use ('diskspace' & 'folders' are particularly handy).
# some more ls aliases
alias ll='ls ...
83
votes
5answers
3k views
How to “cd” into a directory with this name “-2”?
I have a directory named:
-2
I want to cd into it but the cd complains:
bash: cd: -2: invalid option
With no success, I've tried:
cd "-2"
cd '-2'
cd \-2
Any solution?
Edit: no file browsers ...
76
votes
25answers
18k views
How do I prevent accidental rm -rf /*?
I just ran rm -rf /* accidentally, but I meant rm -rf ./* (notice the star after the slash).
alias rm='rm -i' and --preserve-root by default didn't save me, so are there any automatic safeguards for ...
61
votes
7answers
51k views
How to zip/unzip files in Powershell?
Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
61
votes
5answers
136k views
Does Windows have a built-in ZIP command for the command line?
Since Windows Explorer (since at least Windows XP) has some basic support for ZIP files, it seems like there should be a command-line equivalent, but I can't seem to find any sign of one.
Does ...
50
votes
11answers
34k views
What are useful .screenrc settings?
Basically like some of my own that I've posted below. I'm looking for added functionality to the programme 'screen'. At the very least have a look at the last line for a fantastic 'menu bar' at the ...
46
votes
7answers
75k views
Run a .bat file in a scheduled task without a window
I have a scheduled task that starts a batch script that runs robocopy every hour. Every time it runs a window pops up on the desktop with robocopy's output, which I don't really want to see.
I ...
38
votes
10answers
70k views
Run Oracle SQL script and exit from sqlplus.exe via command prompt
I would like to run an Oracle script through SQL Plus via a Windows command prompt. The script does not contain an "exit" command, but I would still like SQL Plus to exit, returning control to the ...
35
votes
81answers
5k views
Biggest command-line mistake? [closed]
This question exists because it has
historical significance, but it is not
considered a good, on-topic question
for this site, so please do not use it
as evidence that you can ask similar
...
35
votes
52answers
4k views
Favorite Unix command line aliases? [closed]
What are your favorite command line aliases (bash/sh/tcsh) aliases? Here are a few of mine.
alias lsr='ls -lrt'
alias gon='cd $HOME/Notes'
alias devdb='mysql -h dev --user=x --password=secret ...
34
votes
30answers
4k views
Command line safety tricks [closed]
Command line and scripting is dangerous. Make a little typo with rm -rf and you are in a world of hurt. Confuse prod with stage in the name of the database while running an import script and you are ...
33
votes
7answers
25k views
What is the Windows equivalent of Unix “whoami” command?
Is there a Windows equivalent of Unix "whoami" command? If so, what is it?
32
votes
42answers
5k views
Tools a Unix administrator cannot live without [closed]
After administering Unix or Unix-like servers, what tools (command-line preferably) do you feel you cannot live without?
29
votes
1answer
4k views
What is the difference between a 'Login' and an 'Interactive' bash shell
What is the difference between a ‘Login’ and an ‘Interactive’ bash shell?
I have quoted Wikipedia below but can anybody give a better answer?
EDIT: This is a community wiki so maybe rather than ...
27
votes
6answers
1k views
Smoothest workflow to handle SSH host verification errors?
This is a simple issue that we all face and probably resolve manually without giving much thought.
As servers change, are re-provisioned, or IP addresses reallocated, we receive the SSH host ...
25
votes
1answer
3k views
How can I connect to a Windows server using a Command Line Interface? (CLI)
Especially with the option to install Server Core in Server 2008 and above, connecting to Windows servers over a CLI is increasingly useful ability, if not one that's very widespread amongst Windows ...
22
votes
5answers
21k views
How do I find the UUID of a partition
I'm running Ubuntu, and want to find out the UUID of a particular partition. I know I can use e2label /dev/sda1 to find out the partition label, but there doesn't seem to be a similar way to find the ...
21
votes
5answers
19k views
Recursive text search with grep and file patterns
Given this example folder structure:
/folder1/file1.txt
/folder1/file2.djd
/folder2/file3.txt
/folder2/file2.fha
How do I do a recursive text search on all *.txt files with grep from "/"?
("grep ...
19
votes
5answers
1k views
Avoid to keep command in history
I use bash and I would like to avoid some commands being kept in the history.
Is it possible to do that for the next command only?
Is it possible to do that for the entire session?
17
votes
7answers
20k views
Delete Files Older than (x) Days?
What's a good Windows command line option for deleting all files in a given folder older than (n) days?
Also note there may be many thousands of these files, so forfiles with a shell to cmd is not a ...
16
votes
2answers
2k views
What is the command to flash a NIC link light?
I remember using a command line tool to flash a NIC's link light to identify it. I can't remember for the life of me what it was.
14
votes
6answers
34k views
How to take ownership of files from the command line?
Every so often I run into a file that I need to take ownership of. I normally use cacls for changing ntfs permissions, but it doesn't seem to do ownership. Under *nix I would run something like ...
14
votes
3answers
11k views
How to sort ps output by process start time?
Is there a way to sort ps output by process start time, so newest are either at the top or bottom ?
On Linux ?
On SysV5 ?
On Mac ?
14
votes
2answers
17k views
How to display certain lines from a text file in Linux?
I guess everyone knows the useful Linux cmd line utilities head and tail. Head allows you to print the first X lines of a file, tail does the same but prints the end of the file. What is a good ...
14
votes
4answers
13k views
Ssh, run a command on login, and then Stay Logged In?
I tried this with expect, but it didn't work: it closed the connection at the end.
Can we run a script via ssh which will log into remote machines, run a command, and not disconnect?
So ssh in a ...
13
votes
10answers
963 views
What *nix based command can I use to find my external IP?
Similar to a http://whatismyip.com lookup. It would obviously need to query a computer out there. Just wondering if anyone had a clever way to do it?
13
votes
6answers
32k views
How to cp file and create directory if not exists?
I want to copy modified files in a svn repository to another directory, while keep their directory structure.
After reading awk and xargs manpage I find a way to get changed filenames like this:
$ ...
13
votes
3answers
611 views
Strange bash history behaviour when running multiple sessions
How is command line history stored when I use multiple terminal windows? I know it is stored in .bash_history but I can't see the logic on what history is used if I open new window.
It almost feels ...
12
votes
2answers
530 views
What is the difference between sudo -i and sudo su -
What is the difference between commands sudo -i and sudo su -?
Are they the same?
12
votes
2answers
381 views
Using dot (.) as delimiter to specify group in chown
I've always done:
chown nimmylebby:admins file
I see that this also works:
chown nimmylebby.admins file
Might seem like a silly question but I'm genuinely curious on how the latter works. It ...
12
votes
2answers
137 views
Sun Grid Engine huhohshdhjha
when I type qstat -h, I get the following option
[-s {p|r|s|z|hu|ho|hs|hd|hj|ha|h|a}] show pending, running, suspended, zombie jobs,
jobs with a ...
12
votes
4answers
942 views
What's a secure alternative to using a MySQL password on the command line?
We have a PHP command-line script to version a database.
We run this script whenever a developer has added a new database patch.
The script runs the patch with the MySQL command-line:
system('mysql ...
11
votes
5answers
2k views
How do I append a specific number of null bytes to a file?
I have a script that writes to a few files but I need them a specific size. So I'm wondering if there's a way of appending a specific number of null bytes from /dev/zero or however to a file?
11
votes
4answers
3k views
Bash Loop - How to stop the loop when I press Control-C inside a command?
I am rsyncing a few directories. I have a bash terminal open and am executing something like this:
for DIR in * ; do rsync -a $DIR example.com:somewhere/ ; done
However if I want to stop the whole ...
11
votes
4answers
83k views
How to check who is currently logged on to windows workstation from command line?
Environment is in domain, server is Windows Server 2003, workstations have Vista and XP installed.
I need the way to check remotely who is currently logged on workstation, preferably from some simple ...
11
votes
3answers
2k views
Show full process name in top
I'm running a rails stack on ubuntu.
When I ps -AF, I get a descriptive process name set by the apache module like
00:00:43 Rails: /var/www...
which is really helpful in diagnosing load issues.
...
11
votes
4answers
14k views
How can I get diff to show only added and deleted lines? If diff can't do it, what tool can?
How can I get diff to show only added and deleted lines? If diff can't do it, what tool can?
11
votes
6answers
17k views
How to recursively move all files (including hidden) in a subfolder into a parent folder in *nix?
This is a bit of an embarrassing question, but I have to admit that this late in my career I still have questions about the mv command.
I frequently have this problem: I need to move all files ...
11
votes
5answers
4k views
Command line - batch file calling another batch file
I have a batch file which calls another batch file that exists in PATH directory (basically calling an executable with additional switches.)
: bar.bat:
foo.bat file1.txt
foo.bat file2.txt
etc.
In ...
11
votes
4answers
17k views
VPN client connect/disconnect via command line in XP
In an XP Pro workstation, is there a way to start the native Windows VPN client and open/close a connection from the command line so it can be scripted in a batch file?
11
votes
7answers
3k views
I would like to start multiple computers at once, What software do I use?
I have turned on Wake On Lan on all of the BIOSes in the PCs and I have a simple batch file that runs a free command
wolcmd.exe
Wake on Lan Command Line
The syntax is as follows:
wolcmd [mac ...
11
votes
6answers
14k views
KVM Guest installed from console. But how to get to the guest's console?
I'm trying to install a fully virtualized guest (Fedora 14 x86_64) on KVM (RHEL 6), using command-line only (both hypervisor and guest). It goes without errors, and without a tangible result . I'd ...
10
votes
3answers
33k views
Get current directory path in windows command line?
I use %0 in batch file to get the current directory of the batch file but the result is :-
c:\folder1\folder2\batch.bat
I want just directory, without batch file name, like this :-
...
10
votes
7answers
496 views
Why is this file hidden when you run ls?
EDIT: I totally forgot about this thread. It turns out I had a bad hard disk. We had to redeploy this server for other needs so I finally got around to replacing the one bad disk and we're back in ...
10
votes
2answers
216 views
backslash at the beginning of a command
In Installing RVM manual I see a lot of lines starting with '\':
Install RVM with ruby:
$ \curl -L https://get.rvm.io | bash -s stable --ruby
I'd think it is just mistype but they repeat ...
10
votes
4answers
12k views
Linux/Windows/Unix/… file names: Which characters are allowed? Which are unescaped?
Which characters are allowed and which of them must be escaped on the command line in different operating systems?
10
votes
4answers
13k views
Recycle remote IIS app pool from the command line?
Is it possible to recycle an IIS7 app pool from the command line, on a different machine?
I've found APPCMD (appcmd recycle apppool my-app-pool), but it only operates on the host it's run on, AFAICT.
...
10
votes
6answers
7k views
Force local IP traffic to an external interface
I have a machine with several interfaces that I can configure as I want, for instance:
eth1: 192.168.1.1
eth2: 192.168.2.2
I would like to forward all the traffic sent to one of these local ...
10
votes
4answers
492 views
How would you simplify this command?
I'm quite new to strace / netstat / etc. I'm using this command to get a trace of the apache process handling my request (telnet), is there a way to simplify it a bit?
sudo strace -o /tmp/strace -f ...
9
votes
22answers
6k views
Favorite joke/cultural reference in Unix command line form? [closed]
What is your favorite joke or cultural reference expressed as a Unix command line?
