Command Line interface (CLI)

learn more… | top users | synonyms (2)

95
votes
5answers
4k views

How to cd into a directory with this name “-2” (starting with the hyphen)?

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 ...
91
votes
24answers
28k 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 ...
85
votes
8answers
78k views

How to zip/unzip files in Powershell?

Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
82
votes
8answers
139k 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 ...
76
votes
5answers
195k 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 ...
48
votes
10answers
130k 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 ...
41
votes
7answers
41k views

What is the Windows equivalent of Unix “whoami” command?

Is there a Windows equivalent of Unix "whoami" command? If so, what is it?
41
votes
8answers
46k 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 ...
36
votes
52answers
6k 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
1answer
7k 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 ...
33
votes
5answers
3k 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 ...
33
votes
3answers
37k 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 ...
24
votes
6answers
24k 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?
24
votes
4answers
20k 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 ?
23
votes
10answers
74k 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 ...
23
votes
5answers
24k 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 ...
22
votes
8answers
6k views

How to hide a password passed as command line argument?

I'm running a software daemon that requires for certain actions to enter a passphrase to unlock some features which looks for example like that: $ darkcoind masternode start <mypassphrase> ...
22
votes
7answers
30k 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 ...
22
votes
5answers
2k 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?
22
votes
7answers
52k 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 ...
22
votes
2answers
29k views

How to get the url of the current svn repo?

I have 2 svn checkouts that someone setup for me. Now I need to check these same files on another computer, but since I didn't check them out initially I don't know the urls to use when running the ...
20
votes
4answers
157k 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 ...
20
votes
4answers
28k 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?
19
votes
4answers
68k views

Get directory containing the currently executed batch script

I use %0 in batch file to get the containing directory of the batch file but the result is :- c:\folder1\folder2\batch.bat I want just directory, without batch file name, like this :- ...
19
votes
2answers
6k 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.
19
votes
4answers
18k 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 ...
17
votes
3answers
9k 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. ...
17
votes
6answers
6k 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 ...
17
votes
3answers
19k views

Find out symbolic link target via command line

Say that I setup a symbolic link: ln -s /root/Public/mytextfile.txt /root/Public/myothertextfile.txt is there a way to see what the target of myothertextfile.txt is using the command line?
16
votes
7answers
16k 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 ...
16
votes
4answers
7k 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 ...
16
votes
6answers
28k 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 ...
15
votes
6answers
8k views

How do I append a specific number of null bytes to a file? [closed]

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?
15
votes
10answers
2k 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?
15
votes
4answers
24k 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. ...
15
votes
2answers
819 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 ...
14
votes
2answers
4k 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?
14
votes
4answers
29k 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?
14
votes
7answers
39k 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
16answers
36k views

Shell Command for Getting IP Address?

Is there a bash command to find the IP address for an Ubuntu box? I need to find the IP address so I can ssh into the machine later.
13
votes
1answer
6k views

GNU less: How can I search while ignoring case sensitivity without using less -I option?

From GNU less manpage -i or --ignore-case Causes searches to ignore case; that is, uppercase and lowercase are considered identical. This option is ignored if any uppercase ...
13
votes
3answers
1k 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
10answers
18k views

What's the reverse DNS command line utility?

What's the command to find the name of a computer given its IP address? I always forget what this command is, but I know it exists in Windows and I assume it exists on the *nix command-line.
12
votes
2answers
2k views

Linux/Debian - What does 'pee' in moreutils do?

I recently discovered the 'moreutils' package in Debian (and Ubuntu). It's a collection of convenient unix tools. One of the commands is 'pee'. The man page says: pee is like tee but for pipes. ...
12
votes
3answers
9k views

Using bash, how can i find out the average, max and min from a list of numbers?

I have a series piped greps, awks and seds which produce a list of numbers, one on each line. Something like this: 1.13 3.59 1.23 How can i pipe this to something which will output the average, ...
12
votes
3answers
22k views

How can I query my system via command line to see if a KB patch is installed?

I'm looking to find out if a KB is installed via command line.
12
votes
6answers
26k 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 ...
12
votes
2answers
617 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 ...
12
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 ...
12
votes
2answers
192 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 ...