E-learning module "Linux Basics"
Useful Commands II
Other useful commands including examples are:
$ head
→ Print the first lines of a file.
$ head -n 1 .bash_history
Passwd
$ tail
→ Print the last lines of a file.
$ tail -n 2 .bash_history
cd /usr/share/eclipse/dropins/
cd ~
$ cut
→ Cuts the lines of a file into segments and provides access to these segments.
$ cut -d' ' -f1 .bash_history
→ Cuts the lines in single words and displays the first word.
$ wc
→ Displays the number of lines, words and bytes of a file.
$ wc filename
1695 4804 43904 filename
→ 1695 lines, 4804 words and 43904 bytes.
$ sort
→ Sort the lines of a text file.
$ uniq
→ Eleminate or report duplicate lines.
$ find
→ Search through a directory hierarchy based on given criteria for files or directories.- Many different types of criteria are supported, e.g. age, name, type, date, size and so on.
- An additional command can be applied on the result files (e.g. delete).
- Several criteria can be combined (AND, OR) or negated. By default, critera are combined with AND.
$ find $HOME -iname "*cdt*" -type f
/home/user/Desktop/Downloads/eclipse-cdt-pkgbuild.tar.xz
$ grep
→ Displays the lines of a file matching a pattern. Can be used recursively to search through all files within a directory tree (the depth can be chosen).
$ grep -i cd .bash_history
→ Displays all lines of the file .bash_history
which contain the pattern cd
while ignoring upper and lower cases. Sample output: cd Desktop
find $HOME -iname "*cdt*" -type f
![]() | 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). |