sudo [Command] Grant access when permission denied
sudo -i Grant access for root directory
[1st Command] | [2nd Command] Take the output from 1st command to run 2nd command, also called piping
[1st Command] && [2nd Command] Only run the 2nd command if the 1st command was successful
[Start of Range]..[End of Range] Useful for bulk creation
touch file_{1..12}.txt
Can't applied to month
[1st Data];[2nd Data] Grouping different data into single line command
(hostname; date) > info.log
\[Text] \ tell system treats any special character inside text as normal character. Exp:
echo $PATH return /usr/bin:/usr/sbin...
echo \$PATH return $PATH (Treat $ as normal character)
'[String]' Grouping more than one words
history | grep ’touch log*‘
[Command 1] $([Command 2]) Pass Command 2 return to Command 1
tuned-adm profile $(tuned-adm recommend)
Ctrl + c Force stopping the command progress
Ctrl + d Stop the command progress after the process done
q Quit process for some command
clear Clear screen (equivalent to Ctrl + l)
echo $[Variable] Display variable value on terminal
printf "[Command]\n" Display command on terminal, more consistent than echo across platform
cd .. Moves up one folder level
cd ~ Returns to home directory
cd / Returns to root directory
pwd Shows current directory
ls -a -1 List all files (include hidden + each file details) under current directory
rm -rf [File/Directory name] Force deletes file/directory
touch [File name] Create file
mkdir -p [Directory name] Create directory
[Command] 2> dev/null Ignore error result
cat -b [File name] Extract all data from file, useful read text file without open text editor
[Command]| grep -B1 -A1 "[Text]" Search text in the result of command, show one line before and after the text
source [File name]
Run every line inside the file. Exp:
echo "clear" > test.txt (Create text file which contain one line text only)
source test.txt (clear command is run and the screen is cleared)
cut -d [Delimiter] -f [Column No.] [File name] | sort
Filter the result. Exp:
Original data:
root: x:0:0:Super user:/root:/bin/bash
student: x:1000:1000:student:/home/student:/bin/bash
...
Command: cut -d : -f 1 /etc/passwd | sort
Result:
root
student
...
awk -F [Field Separator] ' [Text] { print $[Column No.] }' [File name]
Separate data by field. Exp:
Original data: student: x:1000:1000:student:/home/student:/bin/bash
Command: awk -F : '/student/ { print $4 }' /etc/passwd
Result: 1000