Unix Commands¶
Commands are little programs that do a specific thing. For example, the
date
command shows the current date and time. It will work by simply
typing date
.
Options : Commands have options to change their behavior. They
are optional. For example: date --universal
will print the date in
Coordinated Universal Time. Options usually have a short and a long
form. In this case, you could also have typed date -u
.
Arguments : Arguments are like options, but mandatory. They
usually specify a file on which the command should work. For example, to
remove a file, you use rm
. It clearly needs to know which file to
delete, so it takes one or more arguments: rm file1.txt file2.txt
.
Conventions : Every command has its own rules on how to write options and arguments, so each of them is different. Sometimes the order is not important, sometimes it is. Some commands take options before arguments, others vice versa. There are however some conventions that apply to many (but not all!) commands:
- Options go before arguments.
- Order of options doesn't matter.
- Options have short forms and long forms.
- Long options look like:
--all
,--list
- Short options look like:
-a
,-l
- Short options can be combined:
-a -r -v
can be written as-arv
- Some options take an argument. Usually like:
--input=file.txt
, short form:-i file.txt
- There is usually a
--help
option. - There is usually a
--version
or-v
option to check the command version.
Manual Every command has different options and arguments.
These can be checked using the man
command for manual. For example:
man date
or man rm
. Press q
to quit man
.
Running in the background The ampersand (&
) at the end of a
command runs the command and gives you the prompt back right away. This
way you can continue to type more commands.
List of Commonly used Commands¶
Command | Description |
---|---|
Essential | |
man somecommand |
Shows help page for some command. E.g. man ls .Press q to quit |
somecommand --help |
Shows help for some command. Doesn't work on all commands |
Navigation and File operations | |
ls |
Shows content of directory ( list ) |
ls -l |
Shows content in list form |
ls -a |
Shows hidden files as well ( starting with dot . ) |
ls -lh |
Shows contents of dir, with human-readable filesizes |
cd mydir |
Change current directory to mydir |
cd .. |
Change current directory to parent directory |
cd ~ |
Change current directory to your home directory |
touch a |
Create an empty file named a |
mkdir a |
Create an empty folder named a |
pwd |
Shows the directory you are working in |
cp a b |
Copy file a to b |
cp -r a b |
Copy folder a (recursively) to b |
mv a b/ |
Move file or folder a into folder b |
mv a b |
Rename file or folder a to b |
rm a |
Remove (DELETE) file a |
rm -r a |
Remove (DELETE) folder a and everything in it |
cat a |
Shows the contents of the file a |
head a |
Shows the first few lines of the file a |
tail a |
Shows the last few lines of the file a |
less a |
Interactively show file, allows scrolling using arrow keys. Press q to quit |
System monitoring commands | |
top |
View a list of running processes and the resource usage. Press q to quit |
htop |
Same as top, but more user-friendly interface |
Network related commands | |
ssh johndoe@example.com |
Connect to server example.com with username johndoe .See ssh |
scp a b |
Copy file a to b , where a and b describe paths on a server.scp ~/letter.txt johndoe@example.com:/home/johndoe |
exit |
Close session / Disconnect from server |
wget URL |
Download file at location URL to disk |
Searching Through files | |
grep someword a |
Show only lines in file a that contain someword |
less a |
Press / and type a query to search. |