Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Linux Bash Shell Cheat Sheet, Cheat Sheet of Computer Communication Systems

Linux Bash Shell Cheat Sheet: Basic Commands

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

gaurish
gaurish 🇺🇸

4.7

(15)

235 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
freeworld.posterous.com
Linux Bash Shell
Cheat Sheet
(works with about every distribution, except for apt-get which is Ubuntu/Debian exclusive)
Legend:
Everything in “<>” is to be replaced, ex: <fileName> --> iLovePeanuts.txt
Don't include the '=' in your commands
'..' means that more than one file can be affected with only one command ex: rm
file.txt file2.txt movie.mov .. ..
pf3
pf4
pf5

Partial preview of the text

Download Linux Bash Shell Cheat Sheet and more Cheat Sheet Computer Communication Systems in PDF only on Docsity!

freeworld.posterous.com

Linux Bash Shell

Cheat Sheet

(works with about every distribution, except for apt-get which is Ubuntu/Debian exclusive)

Legend:

Everything in “<>” is to be replaced, ex: --> iLovePeanuts.txt

Don't include the '=' in your commands

'..' means that more than one file can be affected with only one command ex: rm

file.txt file2.txt movie.mov .. ..

Basic Commands

Basic Terminal Shortcuts Basic file manipulation

CTRL L = Clear the terminal cat = show content of file CTRL D = Logout (less, more) SHIFT Page Up/Down = Go up/down the terminal head = from the top CTRL A = Cursor to start of line -n <#oflines> CTRL E = Cursor the end of line CTRL U = Delete left of the cursor tail = from the bottom CTRL K = Delete right of the cursor -n <#oflines> CTRL W = Delete word on the left CTRL Y = Paste (after CTRL U,K or W) mkdir = create new folder TAB = auto completion of file or command mkdir myStuff .. CTRL R = reverse search history mkdir myStuff/pictures/ .. !! = repeat last command CTRL Z = stops the current command (resume with fg in foreground or bg in background) cp image.jpg newimage.jpg = copy and rename a file

Basic Terminal Navigation cp image.jpg / = copy to folder

cp image.jpg folder/sameImageNewName.jpg ls -a = list all files and folders cp -R stuff otherStuff = copy and rename a folder ls = list files in folder cp *.txt stuff/ = copy all of * to folder ls -lh = Detailed list, Human readable ls -l *.jpg = list jpeg files only mv file.txt Documents/ = move file to a folder ls - lh = Result for file only mv = move folder in folder mv filename.txt filename2.txt = rename file cd = change directory mv stuff/newfileName if folder name has spaces use “ “ mv / .. = move folder up in hierarchy cd / = go to root cd .. = go up one folder, tip: ../../../ rm .. = delete file (s) rm -i .. = ask for confirmation each file du -h: Disk usage of folders, human readable rm -f = force deletion of a file du -ah: “ “ “ files & folders, Human readable rm -r / = delete folder du -sh: only show disc usage of folders touch = create or update a file pwd = print working directory ln file1 file2 = physical link man = shows manual (RTFM) ln -s file1 file2 = symbolic link

Basic Commands

Time settings (continued)

date = view & modify time (on your computer) crontab = execute a command regularly -e = modify the crontab View: -l = view current crontab date “+%H” --> If it's 9 am, then it will show 09 -r = delete you crontab date “+%H:%M:%Ss” = (hours, minutes, seconds) In crontab the syntax is %Y = years <Day of week (0-6, Modify: 0 = Sunday)> MMDDhhmmYYYY Month | Day | Hours | Minutes | Year ex, create the file movies.txt every day at 15:47: 47 15 * * * touch /home/bob/movies.txt sudo date 031423421997 = March 14th^ 1997, 23:42 * * * * * --> every minute at 5:30 in the morning, from the 1st^ to 15 th^ each month:

Execute programs at another time 30 5 1-15 * *

at midnight on Mondays, Wednesdays and Thursdays: use 'at' to execute programs in the future 0 0 * * 1, 3 , every two hours: Step 1, write in the terminal: at ENTER 0 */2 * * * ex --> at 16:45 or at 13:43 7/23/11 (to be more precise) every 10 minutes Monday to Friday: or after a certain delay: */10 * * * 1- at now +5 minutes (hours, days, weeks, months, years)

Step 2: ENTER Execute programs in the background

repeat step 2 as many times you need Step 3: CTRL D to close input Add a '&' at the end of a command ex --> cp bigMovieFile.mp4 & atq = show a list of jobs waiting to be executed nohup: ignores the HUP signal when closing the console atrm = delete a job n° (process will still run if the terminal is closed) ex (delete job #42) --> atrm 42 ex --> nohup cp bigMovieFile.mp sleep = pause between commands jobs = know what is running in the background with ';' you can chain commands, ex: touch file; rm file you can make a pause between commands ( m inutes, h ours, d ays) fg = put a background process to foreground ex --> touch file; sleep 10; rm file <-- 10 seconds ex: fg (process 1), f%2 (process 2) f%3, ...

Basic Commands

Process Management Create and modify user accounts

w = who is logged on and what they are doing sudo adduser bob = root creates new user sudo passwd = change a user's password tload = graphic representation of system load average sudo deluser = delete an account (quit with CTRL C) addgroup friends = create a new user group ps = Static process list delgroup friends = delete a user group -ef --> ex: ps -ef | less -ejH --> show process hierarchy usermod -g friends = add user to a group -u --> process's from current user usermod -g bob boby = change account name usermod -aG friends bob = add groups to a user with- top = Dynamic process list out loosing the ones he's already in While in top:

  • q to close top File Permissions
  • h to show the help
  • k to kill a process chown = change the owner of a file ex --> chown bob hello.txt CTRL C to top a current terminal process chown user:bob report.txt = changes the user owning report.txt to 'user' and the group owning it to 'bob' kill = kill a process -R = recursively affect all the sub folders You need the PID # of the process ex --> chown -R bob:bob /home/Daniel ps -u | grep Then chmod = modify user access/permission – simple way kill .. .. .. u = user kill -9 = violent kill g = group o = other killall = kill multiple process's ex --> killall locate d = directory (if element is a directory) l = link (if element is a file link) extras: r = read (read permissions) sudo halt <-- to close computer w = write (write permissions) sudo reboot <-- to reboot x = eXecute (only useful for scripts and programs)

Basic Commands

Archive and compress data (continued) Installing software

step 4, to decompress the .tar file: When software is available in the repositories: tar -xvf archive.tar archive.tar sudo apt-get install ex--> sudo apt-get install aptitude Archive and compress data the fast way: If you download it from the Internets in .gz format gzip: tar -zcvf my_archive.tar.gz folder/ (or bz2) - “Compiling from source” decompress: tar -zcvf my_archive.tar.gz Documents/ Step 1, create a folder to place the file: mkdir /home/username/src <-- then cd to it bzip2: tar -jcvf my_archive.tar.gz folder/ decompress: tar -jxvf archive.tar.bz2 Documents/ Step 2, with 'ls' verify that the file is there (if not, mv ../file.tar.gz /home/username/src/) Show the content of .tar, .gz or .bz2 without decompressing it: Step 3, decompress the file (if .zip: unzip ) gzip: <-- gzip -ztf archive.tar.gz Step 4, use 'ls', you should see a new directory bzip2: Step 5, cd to the new directory bzip2 -jtf archive.tar.bz2 Step 6.1, use ls to verify you have an INSTALL file, tar: then: more INSTALL tar -tf archive.tar If you don't have an INSTALL file: Step 6.2, execute ./configure <-- creates a makefile tar extra: Step 6.2.1, run make <-- builds application binaries tar -rvf archive.tar file.txt = add a file to the .tar Step 6.2. 2 : switch to root --> su Step 6.2. 3 : make install <-- installs the software You can also directly compress a single file and view the file Step 7, read the readme file without decompressing: Step 1, use gzip or bzip2 to compress the file: gzip numbers.txt Step 2, view the file without decompressing it: zcat = view the entire file in the console (same as cat) zmore = view one screen at a time the content of the file (same as more) zless = view one line of the file at a time (same as less)