Linux Bash Shell Cheat Sheet

Pages: 11 (1361 words) Published: April 19, 2014
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 .. ..

Linux Bash Shell Cheat Sheet
Basic Commands
Basic Terminal Shortcuts

Basic file manipulation

CTRL L = Clear the terminal
CTRL D = Logout
SHIFT Page Up/Down = Go up/down the terminal
CTRL A = Cursor to start of line
CTRL E = Cursor the end of line
CTRL U = Delete left of the cursor
CTRL K = Delete right of the cursor
CTRL W = Delete word on the left
CTRL Y = Paste (after CTRL U,K or W)
TAB = auto completion of file or command
CTRL R = reverse search history
!! = repeat last command

cat = show content of file
(less, more)
head = from the top
-n

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
cp
cp
cp

image.jpg / = copy to folder
image.jpg folder/sameImageNewName.jpg
-R stuff otherStuff = copy and rename a folder
*.txt stuff/ = copy all of * to folder

mv
mv
mv
mv
mv

file.txt Documents/ = move file to a folder
= move folder in folder
filename.txt filename2.txt = rename file
stuff/newfileName
/ .. = move folder up in hierarchy

rm
rm
rm
rm

.. = delete file (s)
-i .. = ask for confirmation each file
-f = force deletion of a file
-r / = delete folder

ls
ls
ls
ls
ls

-a = list all files and folders
= list files in folder
-lh = Detailed list, Human readable
-l *.jpg = list jpeg files only
-lh = Result for file only

cd = change directory
if folder name has spaces use “ “
cd / = go to root
cd .. = go up one folder, tip: ../../../
du -h: Disk usage of folders, human readable
du -ah: “

“ files & folders, Human readable
du -sh: only show disc usage of folders

tail = from the bottom
-n
mkdir = create new folder
mkdir myStuff ..
mkdir myStuff/pictures/ ..

touch = create or update a file
pwd = print working directory
man = shows manual (RTFM)

ln file1 file2 = physical link
ln -s file1 file2 = symbolic link

Linux Bash Shell Cheat Sheet
Basic Commands
Researching Files

Extract, sort and filter data

The slow method (sometimes very slow):

grep = search for text in file
-i = Doesn't consider uppercase words
-I = exclude binary files
grep -r / = search for file names
with occurrence of the text

locate = search the content of all the files
locate = search for a file
sudo updatedb = update database of files
find
find
find
find

= the
-name
-name
-name

best file search tool (fast)
“”
“text” = search for files who start with the word text
“*text” = “



end





Advanced Search:
Search from file Size (in ~)
find ~ -size +10M = search files bigger than.. (M,K,G)
Search from last access
find -name “” -atime -5
('-' = less than, '+' = more than and nothing = exactly)
Search only files or directory’s
find -type d --> ex: find /var/log -name "syslog" -type d
find -type f = files
More info: man find, man locate

With regular expressions:
grep
with
grep
grep
with

-E ^ = search start of lines
the word text
-E =shows lines containing numbers 0-4
-E = retrieve all lines
alphabetical letters

sort
sort
sort
sort
sort
sort

= sort the content of files
= sort alphabetically
-o = write result to a file
-r = sort in reverse
-R = sort randomly
-n = sort numbers

wc = word count
wc = nbr of line, nbr of words, byte size
-l (lines), -w (words), -c (byte size), -m
(number of characters)
cut = cut a part of a file
-c --> ex: cut -c 2-5 names.txt
(cut the characters 2 to 5 of each line)
-d (delimiter)
(-d & -f good for .csv files)
-f...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Essay about cheat sheet
  • cheat sheet Essay
  • Cheat Sheet Essay
  • Cheat Sheet Essay
  • Essay on cheat sheet
  • ids cheat sheet Essay
  • Apa Format Cheat Sheet Essay
  • Sql Cheat Sheet Essay

Become a StudyMode Member

Sign Up - It's Free