E-learning module "Linux Basics"
Useful Commands I
Below, you can find some useful commands including examples.
$ more
→ Display a text file „page by page“. Often replaced by less
nowadays.
$ less
→ Display a text file.
$ cat
→ Display the content of a file.
$ du
→ Show the space occupied by directories and files.$ du -sh .
→ Space used in the current directory.
$ file filename
→ Identify the type of the file filename
. The idenfication is based on so called „magic numbers“, this means that file extensions are meaningless!
$ touch
→ Change the time stamp of a file. It can also be used to create an (empty) file.
$ touch file.txt
$ ls -lh
-rw-r--r-- 1 user1 users 0 16. Nov 15:30 file.txt
$ mkdir
→ make directories. Create one or more directories or subdirectories.
$ mkdir dirname
$ mkdir dir1/dir2
→ create the directory dir2 below dir1.
$ diff
→ Display the differences between two files or directories.
$ diff file1 file2
$ diff dir1 dir2
$ cp
→ copy. Copy files.$ cp -r
→ Copy directories.
$ cp file1 file2
$ cp file1 dir1/file1
$ cp file1 dir1/file2
→ What is the difference?$ cp -r dir1 dir2/dir3
$ mv
→ move. Move or rename files or directories.
$ mv dir1 dir2/
→ move dir1
to direcory dir2
.
$ mv dir1 dir2/dir3
→ move and rename.$ mv file1 file2
→ remame.
$ rm
→ Delete file.$ rm -r
→ Delete directories.
$ rm -rf
→ This also deletes directories. What is the difference?
$ rmdir
→ Alternative command to remove directories.
![]() | The content of this e-learning module is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license (CC BY-NC-SA 3.0 DE). |