Philosophy of using command line is that input and output files are files.
Basic Commands:
Correct grammar of command is: verb adverb object
where adverb
is the flag you add to a command e.g -hl
in ls -hl
To view the flags for a command use man
e.g man ls
cd -
go back to previous directory you were inls
list files in a directoryls -hl
more human readable version ofls -l
ls -t
order by modification date, newest first
cp
copy a filecp data1 data3
copies adata1
file todata3
cp -r
to copy a folder with files insiderm
remove a filemv
changes a file namecat
output contents of the filehead
output top part of the file- use
-n
flag to choose the number of lines e.g-5
- use
tail
print top part of the file
less
opens a pager to view a file- within the pager can use
/
to search in the file then pressn
to search for the next file.
- within the pager can use
grep
is used to search a file e.ggrep "fish" king-lear.txt
- to count the number of lines in a text file add
-c
tag grep -c "fish" king-lear.txt
- to be case insensitive use
-i
- use regular expressions with grep for example wildcard
*
- search in all files and files in subdirectories with
-r
tag
Shell scripts are just a text file where we can store linux commands
- to count the number of lines in a text file add
Useful
- Making google chrome the default application to open
.pdf
extensions, run in terminal:
1
xdg-mime default google-chrome.desktop application/pdf