Linux commands
- January 11th, 2011
- Posted in Computer . Linux . OS
- Write comment
I am very forgettable, so I will collect some Linux commands that are useful to me. This is by no means a complete documentation of each command.
lsLists contents of a folder. Example:
martin@darkcloud:~$ ls Desktop hs_err_pid2413.log Programs scripts workspace Documents Music Public Templates Downloads Pictures resources Videos
Nicer output can be achieved by using:
ls -lh
The argument -l lists folder content by line. -h makes folder content sizes human readable. Example:
martin@darkcloud:~$ ls -lh total 132K drwxr-xr-x 2 martin martin 4,0K 2010-12-20 09:24 Desktop drwxr-xr-x 4 martin martin 4,0K 2010-12-22 10:39 Documents drwxr-xr-x 14 martin martin 20K 2011-01-11 09:44 Downloads -rw-r--r-- 1 martin martin 76K 2011-01-11 12:06 hs_err_pid2413.log ...
Another important argument for ls is -a, which shows hidden folder content.
ls -a
Folder size:
du -sh folder/
When using the command cut, the delimiter is selectable with the -d option. If the delimiter is supposed to be TAB, hit <CTRL>v<TAB> to put the TAB between the quotation marks.
cut -d"<CTRL>v<TAB>"
Another example using file tools, is to extract the second column with delimiter : of the file doc_tags.sql (cut -d":" -f2 doc_tags.sql) sort the output (sort), extract unique entries and count the duplicates (uniq -c) and finally count the number of unique entries (wc). OK, counting the duplicates does not get us anywhere as we only count lines with the wc command (first number), but this is for illustration purposes, so whatever.
cut -d" " -f2 doc_tags.sql | sort | uniq -c | wc
Count files in directory dir:
find dir -type f | wc -l
Find and count empty files in dir:
find dir -type f -empty | wc -l
No comments yet.