Linux Bash Shell Cheat Sheet
Linux Bash Shell Cheat Sheet
Linux Bash Shell Cheat Sheet
com
Le end% &verythin in '()* is to be replaced, ex% (file+ame) --) iLove,eanuts.txt #on-t include the -.- in your commands -..- means that more than one file can be affected with only one command ex% rm file.txt file/.txt movie.mov .. ..
ima e.=p (folder+ame)" . copy to folder ima e.=p folder"same3ma e+ew+ame.=p -1 stuff otherStuff . copy and rename a folder >.txt stuff" . copy all of >(file type) to folder file.txt #ocuments" . move file to a folder (folder+ame) (folder+ame/) . move folder in folder filename.txt filename/.txt . rename file (file+ame) stuff"newfile+ame (folder+ame)" .. . move folder up in hierarchy (file+ame) .. . delete file (s$ -i (file+ame) .. . ask for confirmation each file -f (file+ame) . force deletion of a file -r (foldername)" . delete folder
cd (folder+ame) . chan e directory if folder name has spaces use ' ' cd " . o to root cd .. . o up one folder, tip% .."..".." du -h% #isk usa e of folders, human readable du -ah% ' ' ' files ? folders, 2uman readable du -sh% only show disc usa e of folders pwd . print workin directory
touch (file+ame) . create or update a file man (command) . shows manual (104A$ ln file@ file/ . physical link ln -s file@ file/ . symbolic link
6dvanced Search%
Search from file SiEe (in F$ find F -siEe G@CA . search files bi er than.. (A,8,5$
Search from last access find -name '(filetype)* -atime -H (--- . less than, -G- . more than and nothin Search only files or directoryIs find -type d --) ex% find "var"lo find -type f . files Aore info% man find, man locate
. exactly$
wc . word count wc (file+ame) . nbr of line, nbr of words, byte siEe -l (lines$, -w (words$, -c (byte siEe$, -m (number of characters$ cut . cut a part of a file -c --) ex% cut -c /-H names.txt (cut the characters / to H of each line$ -d (delimiter$ (-d ? -f ood for .csv files$ -f (7 of field to cut$ more info% man cut, man sort, man rep
(continued$
crontab . execute a command re ularly -e . modify the crontab -l . view current crontab -r . delete you crontab 3n crontab the syntax is (Ainutes) (2ours) (#ay of month) (#ay of week (C-N, C . Sunday$) (COAA6+#) ex, create the file movies.txt every day at @H%DQ% DQ @H > > > touch "home"bob"movies.txt > > > > > --) every minute at H%RC in the mornin , from the @st to @Hth each month% RC H @-@H > > at midni ht on Aondays, 9ednesdays and 0hursdays% C C > > @,R,D every two hours% C >"/ > > > every @C minutes Aonday to 4riday% >"@C > > > @-H
. put a back round process to fore round ex% f (process @$, fL/ (process /$ fLR, ...
tload . raphic representation of system load avera e (Suit with C01L C$ ps . Static process list -ef --) ex% ps -ef P less -e=2 --) show process hierarchy -u --) process-s from current user top . #ynamic process list 9hile in top% S to close top h to show the help k to kill a process
4ile ,ermissions
chown . chan e the owner of a file ex --) chown bob hello.txt chown user%bob report.txt . chan es the user ownin report.txt to -user- and the roup ownin it to -bob-1 . recursively affect all the sub folders ex --) chown -1 bob%bob "home"#aniel chmod . modify user access"permission V simple way u . user . roup o . other d . l . r . w . x . pro directory (if element is a directory$ link (if element is a file link$ read (read permissions$ write (write permissions$ eWecute (only useful for scripts and rams$
C01L C to top a current terminal process kill . kill a process :ou need the ,3# 7 of the process ps -u (6ccount+ame) P rep (6pplication) 0hen kill (,3#) .. .. .. kill -M (,3#) . violent kill killall . kill multiple process-s ex --) killall locate extras% sudo halt (-- to close computer sudo reboot (-- to reboot
4low redirection
1edirect results of commands% -)- at the end of a command to redirect the result to a file ex --) ps -e=2 ) process.txt -))- to redirect the result to the end of a file
Chain commands
-P- at the end of a command to enter another one ex --) du P sort -nr P less
1edirect errors%
-/)- at the end of the command to redirect the result to a file ex --) cut -d , -f @ file.csv ) file /) errors.lo -/)?@- to redirect the errors the same way as the standard output 1ead pro ressively from the keyboard (Command) (( (word0o0erminate3nput)
ex --) sort (( &+# (-- 0his can be anythin
) ) ) ) ) ) ) 2ello 6lex Cinema 5ame Code !buntu &+#
Step @, put all the files you want to compress in the same folder% ex --) mv >.txt folder" Step /, Create the tar file% tar -cvf myXarchive.tar folder" -c % creates a .tar archive -v % tells you what is happenin (verbose$ -f % assembles the archive into one file
Step R.@, create Eip file (most current$% Eip myXarchive.tar to decompress% unEip myXarchive.tar. E Step R./, or create a bEip/ file (more powerful but slow$% bEip/ myXarchive.tar to decompress% bunEip/ myXarchive.tar.bE/
you want
3nstallin
software
9hen software is available in the repositories% sudo apt- et install (nameOfSoftware) ex--) sudo apt- et install aptitude