Command | Example / Options | Description |
less | less file.txt | Show the content of the text-file. You can move with the cursor-keys. To quit less press the key Q. |
man | man command | Show the man-page (manual-page) of the command. |
man command | col -b > manual.txt | Save the man-page of the command as manual.txt. | |
help | command --help | Show the help of the command. |
command -h | Show the help of the command. | |
ps -h | Show the help of the command ps | |
ps | ps aux | less | Shows your own processes. The column PID shows the process-ID. You can move with the cursor-keys. To quit less press the key Q. |
ps x | grep -i abiword | Shows one process (e.g. abiword). | |
a | Shows all processes. | |
u | Gives further information about the processes. | |
x | Shows your own processes. | |
top | top | Shows all processes. To quit top press Ctrl+C. |
kill | kill -9 5321 | Stops the process 5321. |
which | which abiword | Shows the path to abiword. |
pwd | Shows the full pathname of your working directory (pwd = print working directory). | |
cd | cd directory | Change the current working directory to directory (cd = change directory). |
cd / | Change to the root directory. | |
cd /root/my-documents | Change to the directory /root/my-documents (absolute pathname, this means, the path starts at the root directory). | |
cd my-documents | If your are at the root-directory, you will change to the sub-directory my-documents (relative pathname, this means, the path starts at the working directory). | |
cd .. | Change to the parent directory of the current directory. | |
cd | Change to your home-directory. | |
cd - | Change to the previous directory. With this command you can change between two directories. | |
mkdir | mkdir directory | Makes a new directory (mkdir = make directory). |
mkdir -p pictures/holiday/2004 | Makes the directories /pictures, /pictures/holiday and pictures/holiday/2004 with only one command. | |
rmdir | rmdir -r directory | Remove directory (rmdir = remove directory). Without the option -r rmdir removes only empty directories. |
cp | cp from to | Copies a file or directory (cp = copy). |
cp -i picture.jpg copy.jpg | Makes a copy (copy.jpg) of the file picture.jpg. | |
cp -i picture1.jpg picture2.jpg pictures | Copies the files picture1.jpg and picture2.jpg to the directory pictures. If the files already exist in the target-directory they are overwritten. The target-directory must already exist. | |
cp -r pictures backup | Copies the directory pictures with all sub-directories to the directory backup. | |
-i | interactive. Ask, if an existing file shall be overwritten (confirm with the key y). | |
-b | backup. If the file already exists, the copy-command first makes a backup of the old file (marked with ~, e.g. picture1.jpg~). | |
-r | recursive. All sub-directories are copied, too. | |
? |
Wildcard for one character, e.g. cp picture?.jpg pictures copies the files picture1.jpg, picture2.jpg and picturea.jpg |
|
* |
Wildcard for many characters, e.g. cp *.jpg pictures copies all jpg-files (Attention: Linux is case sensitive. Only jpg-files with the extetnsion jpg are copied, not jpg-files with the extension JPG). |
|
[characters] |
Range. One of the characters in squared brackets must be in the filename, e.g. cp *.[jJ][pP][gG] pictures copies all jpg-files with the extensions jpg, JPG, Jpg and so on. cp picture[a-zA-Z].jpg copies the files picturea.jpg and pictureb.jpg, but not picture1.jpg and picture2.jpg. cp picture[0-9].jpg copies the files picture1.jpg and picture2.jpg, but not picturea.jpg and pictureb.jpg. |
|
mv | mv from to | Moves or renames a file or directory (mv = move). |
mv picture.jpg panorama.jpg | The file picture.jpg is renamed panorama.jpg. | |
mv pictures/backup pictures/backup_old | The directory pictures/backup is renamed into pictures/backup_old. | |
mv -i pictures/2004/picture.jpg pictures/2005 | The file picture.jpg is moved from the directory pictures/2004/ to pictures/2005. The directory pictures/2005 must already exist. | |
-i | interactive. Ask, if an existing file shall be overwritten (confirm with the key y). | |
rm | rm file | Removes a file (rm = remove). |
rm | rm -i "*.jpg" | Removes all jpg-files from the working directory. |
-i | interactive. Asks, if the file should be removed (confirm with the key y). | |
shred | shred -fuv file | Removes the file and overwrites the diskspace 25-times. |
shred -fuv -n 50 file | Removes the file and overwrites the diskspace 50-times. | |
touch | touch file | Makes an empty file. |
du | du /root/my-documents | Shows the size of each subdirectory of /root/my-documents. |
du -m /root/my-documents | sort -n | less | Sorts the directories by size. You can move with the cursor-keys. To quit less press the key Q. | |
ls | ls -al | Lists the all files of your current working directory. |
ls -al pictures/2006 | Lists the all files of the directory picture/2006. | |
-l | Detailed list with filesize, date, permissions. | |
-a | Lists hidden files. | |
-R | Lists all files in your current working directory and all sub-directories. | |
-t | Sort by date of change. | |
-S | Sort by filesize. | |
-r | Reverse sort. | |
ls -rtl | less | Lists the files in reverse order sorted by the date of change | |
ls -rSl | less | Lists the files in reverse order sorted by the filesize. | |
ls -F | grep /$ | Lists only sub-direcotries, not the files. | |
find | find -type f -iname picture.jpg | Shows the path to the file picture.jpg. The search starts at your working directory and includes all sub-directories. You can stop the search by pressing Ctrl+C. Wildcards (?,*) must be set in quotation marks. The option -type f restricts the search to files (f = file, d = directory, l = link). With the option -iname the search is not case sensitive. |
find /root/my-documents -type f -iname picture.jpg | Shows the path to the file picture.jpg. The search starts at the directory /root/my-documents. | |
find -type f -iname "*.jpg" | Finds all jpg-files (extension jpg, not JPG !) | |
find /home/music -type f -iname "*.mp3" | wc -l | Shows, how many files are in the directory /home/music and its sub-directories. | |
find -type f -size +1000k | Finds all files, larger than 1000 Kilobytes. | |
find -type f -size -1000k | Finds all files smaller than 1000 Kilobytes. | |
find -mtime 0 | Finds all files that have been changed in the last 24 hours. | |
find -mtime 2 | Finds all files that have been changed in the last 2 days. | |
find -mmin 5 | Finds all files that have been changed in the last 5 minutes. | |
find /root/my-documents -type f -name "*.*~" -ok rm "{}" ";" | Removes all backup-files from the directory /root/my-documents and its sub-directories (confirm with the key y). If you use the the option -exec instead of the option -ok, the files are removed without confirmation. | |
grep | grep pattern *.txt | Shows all text-files in your working directory containing pattern. The search is case sensitive. |
grep | grep "Linux" *.txt | Shows all text-files in your working directory containing the word "Linux". The search is case sensitive. |
grep -i pattern *.txt | Shows all text-files in your working directory containing pattern. The search is not case sensitive. | |
grep -r pattern | Shows all text-files in your working directory and its sub-directories containing pattern. | |
grep -L pattern *.txt | Shows all text-files not containing pattern. | |
mount | mount | Shows the mounted partitions |
mount /dev/hda3 /mnt/hda3 | Mounts the partition hda3 at /mnt/hda3. | |
umount | umount /dev/hda3 | Unmounts the partition hda3. |
df | df -h | Shows the space on your harddrive. |
du | du -h | Shows the space of a directory. |
du /root | sort -rn | less | Shows, which sub-directories of /root use the most space. | |
ln | ln -s file link | Makes a symbolic link (softlink) in your working directory to the file. |
ln -s /root/projects/summary.txt | Makes a softlink summary.txt in your working directory to the file /root/projects/summary.txt. | |
ln -s /root/projects/summary.txt /root/my-documents/my_summary.txt | Makes a softlink my_summary.txt in the directory /root/my-documents to the file /root/projects/summary.txt. | |
ln -s /root/projects /root/my-documents/ | Makes a softlink in the directory /root/my-documents to the directory /root/projects. | |
ls -l | Shows which files are softlinks and where the original file is (there is an arrow behind the filename pointing to the original file). | |
ln file link | Makes a hardlink to the file in your working directory. A hardlink is an alternative filename of a file. Both, the (original) file and the hardlink are the same file, the same point of your filesystem. There is no difference between the original file and the hardlink. You can create a hardlink just like a softlink without the option -s. | |
ls -l | Shows how many names (hardlinks) a file has. The second column shows the number of hardlinks. | |
cat | cat -n file | less | Shows the content of the (text-)file with line-numbers. |
>
< |
Redirections. | |
ls /home/* > home.txt | Redirects the output of the ls-command to the file home.txt. If the file home.txt already exists, it will be overwritten. If errors occur while running the ls-command, the error messages are written to the shell. | |
ls /home/* >> home.txt | Appends the output of the ls-command to the file home.txt. If the file home.txt does not exist, the file will be created. | |
ls /home/* 2> /dev/null | Redirects errors to /dev/null so you will not see the error messages. | |
ls /home/* > home.txt 2> /dev/null | Redirects the output of the ls-command to the file home.txt, error messages are suppressed. | |
ls /home/* >& home.txt | Redirects the output of the ls-command with all error messages to the file home.txt | |
sort < unsort.txt | Redirects the content of the file unsort.txt to the sort-command. | |
tee | ls -l | tee home.txt | Redirects the output of the ls-command to the file home.txt and to the shell simultaneously. |
head
tail |
tail -n +3 file | head -n 2 | Shows line 3 and 4 of the (text-) file. Tail reads the lines 3 to the end of the file and head shows the first two lines read by tail. |
tail -f file | Shows the last 10 lines of the file. The output is automatically refreshed everytime the file is changed. (e.g. a log-file like /var/log/messages). You can stop tail by pressing Ctrl+C. | |
wc | wc file | Shows how many lines, words and characters the (text-)file contains (wc = word count). |
diff | diff file1 file2 |
Compares two text-files. Diff shows what has to be changed in the first file to get the second file
(first file + diff = second file"). Example:
1c1 The symbols 1c1 mean that the files differ at line 1 (c = change). Then you see the line 1 of the first file (starts with <) and then line 1 of the second file (starts with >). Lines that are only in the second file (they are missing in the first file) are marked with an "a" (a = append):
19a19,25 First you see the line-number of the first file (line 19). Then you see the "a" (append) and then you see the line-numbers of the second file (19-25) that are missing in the first file. |
tar | tar -cvf archiv.tar file1 file2 | Packs up file1 and file2 into archiv.tar. |
tar -czvf archiv.tar.gz file1 file2 | Packs up file1 and file2 into archiv.tar and compresses the file archiv.tar with gzip. | |
tar -rf archiv.tar newfile | Adds newfile to archiv.tar. | |
tar -tvf archiv.tar | Shows the content of archiv.tar. | |
tar -tzvf archiv.tar.gz | Shows the content of the (gzip-) compressed archiv.tar. | |
tar -xvf archiv.tar | Unpacks archiv.tar in your working directory. | |
tar -xzvf archiv.tar.gz | Unpacks the (gzip-) compressed archiv.tar.gz in your working directory. | |
tar -xzvf archiv.tar.gz -C /root/my-documents | Unpacks the (gzip-) compressed archiv.tar.gz in the directory /root/my-documents | |
gzip
bzip2 |
gzip file | Compresses a file (e.g. an archiv) with gzip (gzip is compatible with WinZip). Alternatively you can compress with bzip2 as well. |
cut | cut -f 1,2,3,7 adress.txt > print.txt | Reads out columns 1,2,3 and 7 of the file adress.txt and save the result into the file print.txt. The file adress.txt must be seperated by tabulators. |
cut -d , -f 1,2,3,7 adress.txt > print.txt | Reads out columns 1,2,3 and 7 of the file adress.txt and save the result into the file print.txt. The file adress.txt must be seperated by commas (option -d determines the seperator). | |
cal | cal -m | Calendar. Shows the current month, the week starts at monday (Option -m). |
cal -m -3 | Shows the current month and the month before and after. | |
cal 06 2006 -m | Shows the month June 2006. | |
cal 2007 -m | Shows the whole year 2007. | |
cal -j 09 2007 | Shows the number of the day 15. September 2007. | |
split | split -b 1m bigfile smallfile | The file bigfile is split into 1 megabyte small files. The small files are signed with characters (smallfilea, smallfileb, smallfilec and so on). |
split -b 500k bigfile smallfile | The file bigfile is split into 500 kilobyte small files. | |
cat smallfile* > bigfile | Merges the smallfiles to the bigfile. | |
/sbin/ifconfig | Shows your IP-address. The second line (behind inet addr) shows your IP-adress. | |
history | history -c | Clears the command-history. This command deletes the content of the file /root/.bash_history. |
od | od -h file.txt | Hexadecimal view of the text-file. |
od -c file.txt | ASCII view of the text-file. | |
lame | lame -b 320 song.wav song.mp3 | Convert an audio-file from wave to mp3. The quality is 320 kbps. |
lame -b 192 --ta "artist" --tt "song titel" song.wav song.mp3 | Convert an audio-file from wave to mp3 and write artist and song titel as ID3-tag. The quality is 192 kbps. | |
-b value | Sampling-rate (quality). Maximum: 320 | |
--ta "artist" | Artist | |
--tt "song titel" | Songtitel | |
--tg "genre" | Genre. Enter a number or text, e.g. 13 or "Pop". | |
--tl "album" | Album | |
--tc "comment" | Comment | |
--ty year | Year | |
--tn tracknumber | Tracknumber | |
lame --genre-list | less | Show a list of the genres. You can move with the cursor-keys. To quit less press the key Q. | |
lame --decode song.mp3 song.wav | Convert an audio-file from mp3 to wave. | |
id3v2 | id3v2 -l song.mp3 | Show the ID3-tags of a mp3-file (id3v2 must be installed). |
id3v2 -a "artist" -t "songtitel" song.mp3 | Write the artist and song titel as ID3-tag. | |
-a "artist" | Artist | |
-t "song titel" | Songtitel | |
-g "Genre" | Genre. Enter a number or text, e.g. 13 or "Pop". | |
-A "album" | Album | |
-c "comment" | Comment | |
-y year | Year | |
-T tracknumber | Tracknumber | |
id3v2 -d song.mp3 | Delete the ID3v2-tags. | |
id3v2 -s song.mp3 | Delete the ID3v1-tags. |