Why you should learn command line ?
Though it is difficult to learn command line (CLI), it is the quickest and most efficient way to use a computer for many different tasks.
Lets see what we can do with bash 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
Basic Terminal Navigation
pwd = print working directory
ls = list files and folders
ls -a = list all files and folders (including hidden files)
ls <folderName> = list files in folder
ls -lh = Detailed list, Human readable
ls -l *.jpg = list jpeg files only
ls -lh <fileName> = Result for the file only
cd <folderName> = 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: Disk usage of files & folders, Human readable
du -sh: only show disc usage of folder
Basic File Manipulation
cat <fileName> = show content of file
(less, more)
head = from the top
-n <#oflines> <fileName>
mkdir = create new folder
mkdir myStuff ..
mkdir myStuff/pictures/ ..
cp image.jpg newimage.jpg = copy and rename a file
cp image.jpg <folderName>/ = copy to folder
cp image.jpg folder/sameImageNewName.jpg
cp -R stuff otherStuff = copy and rename a folder
cp *.txt stuff/ = copy all of *<file type> to folder
mv file.txt Documents/ = move file to a folder
mv <folderName> <folderName2> = move folder in folder
mv filename.txt filename2.txt = rename file
mv <fileName> stuff/newfileName
mv <folderName>/ .. = move folder up in hierarchy
rm <fileName> .. = delete file (s)
rm -i <fileName> .. = ask for confirmation each file
rm -f <fileName> = force deletion of a file
rm -r <foldername>/ = delete folder
touch <fileName> = create or update a file
ln file1 file2 = physical link
ln -s file1 file2 = symbolic link
Searching Files
find -name <fileName> = search file by name
find -name "text" = search for files who start with the word text
find -name "*text" = search for files who end with the word text
Extract, sort and filter data
grep <someText> <fileName> = search for text in file
-i = Doesn't consider uppercase words
-I = exclude binary files
grep -r <text> <folderName>/ = search for file names with
occurrence of the text
With regular expressions:
grep with -E ^<text> <fileName> = search start of lines the word textgrep
grep -E <0-4> <fileName> = shows lines containing numbers 0-4
grep -E <a-zA-Z> <fileName> = retrieve all lines alphabetical letters
sort = sort the content of files
sort <fileName> = sort alphabetically
sort -o <file> <outputFile> = write result to a file
sort -r <fileName> = sort in reverse
sort -R <fileName> = sort randomly
sort -n <fileName> = sort numbers
wc = word count
wc <fileName> = number of line, number 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 (# of field to cut)
No comments:
Post a Comment