#
cmd1 && cmd2
cmd1 || cmd2
cmd1; cmd2
cmd1 & cmd2
clear
man <command>
Ctrl+C
Ctrl+Z
Ctrl+W
Ctrl+U
Ctrl+R
exit
Ctrl+D
cmd+up
cmd+down
ctrl+_
ctrl+t
ALT+t
ALT+.
ctrl+x+*
ctrl+arrow
ALT+f
ALT+b
ctrl+x+ctrl+e
ctrl+xx
ctrl+k
ctrl+y
CTRL+L
CTRL+J
CTRL+M
CTRL+N
CTRL+O
CTRL+P
CTRL+S
CTRL+X
Ctrl+A
Ctrl+E
gzip <filename>
gunzip <filename>
gzip -d file.gz
gzcat <filename>
tar cf file.tar files
tar xf file.tar
tar czf file.tar.gz files
tar xzf file.tar.gz
tar cjf file.tar.bz2
tar xjf file.tar.bz2
Step 1, put all the files you want to compress in the same folder:
ex --> mv *.txt folder/
Step 2, Create the tar file:
tar -cvf my_archive.tar folder/
Read progressively from the keyboard
-c : creates a .tar archive
-v : tells you what is happening (verbose) <<
-f : assembles the archive into one file
Step 3.1, create gzip file (most current):
gzip my_archive.tar
to decompress:
gunzip my_archive.tar.gz
Step 3.2, or create a bzip2 file (more powerful but slow):
bzip2 my_archive.tar
to decompress:
bunzip2 my_archive.tar.bz2
step 4, to decompress the .tar file:
tar -xvf archive.tar archive.tar
If you download it from the Internets in .gz format
gzip:
tar -zcvf my_archive.tar.gz folder/
decompress:
tar -zcvf my_archive.tar.gz Documents/
bzip2:
tar -jcvf my_archive.tar.gz folder/
decompress:
tar -jxvf archive.tar.bz2 Documents/
Show the content of .tar, .gz or .bz2 without decompressing it:
gzip:
gzip -ztf archive.tar.gz
bzip2:
bzip2 -jtf archive.tar.bz2
tar:
tar -tf archive.tar
tar extra:
tar -rvf archive.tar file.txt = add a file to the .tar
You can also directly compress a single file and view the file without decompressing:
Step 1, use gzip or bzip2 to compress the file:
gzip numbers.txt
Step 2, view the file without decompressing it:
view the entire file in the console (same as cat)
zcat
view one screen at a time the content of the file (same as more)
zmore
view one line of the file at a time (same as less)
zless
ls
lists your files in 'long format', which contains the exact size of the file, who owns the file and who has the right
ls -l
lists all files, including hidden files
ls -a
formatted listing with hidden files
ls -al
pwd
file filename
ls dirname
ls -lt
ls -ltr
ls -R
ls -lh
-l *.jpg
ln -s <filename> <link>
more <filename>
vi <filename>
less filename
head <filename>
tail <filename>
tail -f file
tail -f path_to_Log
tail -f path_to_log | grep search_term
diff <filename1> <filename2>
wc <filename>
lpr <filename>
cat filename
lpq
lprm <jobnumber>
genscript
dvips <filename>
cat test test1
cat >test2
cat test test1 test2 test3 | sort > test4
grep <pattern> <filenames>
grep -r <pattern> <dir>
grep -r "192.168.1.5" /etc/
fgrep "foobar" file.txt
command | grep pattern
locate <file>
grep 'word' filename
grep -Pri Search_Term path_to_directory
grep -i 'bar' file1
ex. for finding ERROR and Exception
egrep โERROR|Exceptionโ *.xml
Search and display the total number of times that the string โnixcraftโ appears in a file named frontpage.md
grep -c 'nixcraft' frontpage.md
uniq -d file.txt
grep Exception logfile.txt I grep -v ERROR
grep -c "Error" logfile.txt
grep -n <pattern> <file>
grep -n 'root' /etc/passwd
grep --context=6 successful logfile.txt
egrep 'Error|Exception' logfile.txt
grep -i Error logfile
zgrep -i Error *.gz
grep -w ERROR logfile.txt
egrep -w 'word1|word2' /path/to/file
grep 'first\|second\|third' .
grep -Ril 'first\|second\|third' *
grep 'first\|second\|third' filename
grep -l ERROR *.log
touch file
emacs <filename>
mv <filename1> <filename2>
cp <filename1> <filename2>
rm <filename>
rm -f file
Recursive
sudo rm -r -f ./folder
sudo mkdir < dir name >
sudo mkdir
> filename
fallocate -l 24M filename
chmod -options <filename>
chmod
u
g
o
d
l
r
chmod +r filename
w
chmod +w filename
x
chmod +x filename
'+'
'-'
'='
chmod g-w someFile.txt
sudo chmod 0777 fileName
sudo chmod 755
chown
chown bob hello.txt
sudo chown -R username /opt/something/
chown user:bob report.txt
./filename
vi filename
press "i"
Press "Esc"
:wq
:q!
press "u"
:q
:x
mkdir <dirname>
cd
cd <dirname>
pwd
cd -
sudo rm -r dir
sudo rm -rf dir
cp -r dir1 dir2
find filename dir
find / -name wordToFind*
find . -name wordToFInd
whereis filename
which filename
Step 1, write in the terminal: at ENTER ex --> at 16:45 or at 13:43 7/23/11 (to be more precise) or after a certain delay: at now +5 minutes (hours, days, weeks, months, years)
Step 2: ENTER repeat step 2 as many times you need
Step 3: CTRL+D to close input atq = show a list of jobs waiting to be executed atrm = delete a job n. ex (delete job #42) --> atrm 42 sleep = pause between commands with ";" you can chain commands, ex: touch file; rm file
you can make a pause between commands (minutes, hours, dys) ex --> touch file; sleep 10; rm file
<-- 10 seconds
crontab
crontab -e
crontab -1
crontab -r
<Minutes> <Hours> <Day of month> <Day of week (0-6, 0 = Sunday)> <COMMAD>
47 15 * * * touch /home/bob/movies.txt
* * * * *
30 5 1-15 * *
0 0 * * 1,3,4
## Add a '&' at the end of a command
cp bigMovieFile.mp4 &
nohup: ignores the HUP signal when closing the console (process will still run if the terminal is closed)
nohup cp bigMovieFile.mp4
jobs
fg (process 1), f%2 (process 2) f%3, ...
bg
fg
fg <job>
To suspend a job, type CTRL+Z while it is running. You can also suspend a job with CTRL+Y.
This is slightly different from CTRL+Z in that the process is only stopped when it attempts to read input from terminal.
Of course, to interupt a job, type CTRL+C.
myCommand &
fg %+
fg %-
fg %N
fg %string
fg %?string
disown <PID|JID>
wait
fg n
sudo shutdown -P +60
sudo shutdown -P 1:00
sudo shutdown -c
echo "ls -l" | at 07:00
pgm > file
python hello.py > output.txt
pgm < file
python hello.py < foo.txt
pgm >> file
python hello.py >> output.txt
pgm1 | pgm2
<< tag
Note that file descriptor 0 is normally standard input, 1 is standard output, and 2 is standard error output.
>|file
n>|file
<> file
n<>file
n >& m
n <& m
n>&
n<&
&>file
<&-
>&-
n>&-
n<&-
python hello.py 2> error.log
python hello.py 2>/dev/null
python hello.py 2>&1
python hello.py &>/dev/null
ssh user@host
ssh -p <port> user@host
ssh-copy-id user@host
w
ping <host>
whois <domain>
dig <domain>
dig -x <host>
wget <file>
ping host
wget -c file
whoami
passwd
finger <user>
Example: Display information about the user ch.
finger -p ch
Output will appear similar to the following:
Login name: admin In real life: Computer Hope On since Feb 11 23:37:16 on pts/7 from domain.computerhope.com 28 seconds Idle Time Unread mail since Mon Feb 12 00:22:52 2001
last <yourUsername>
Definition
The user and group quotas provide the mechanisms by which the amount of space used by a single user or all users within a specific group can be limited to a value defined by the administrator.
- Soft Limit โ If the user exceeds the limit defined, there is a grace period that allows the user to free up some space.
- Hard Limit โ When the hard limit is reached, regardless of the grace period, no further files or blocks can be allocated.
quota
edquota
quotacheck
setquota
quotaon
quotaoff
repquota
who
sudo adduser bob
sudo passwd <AccountName>
sudo deluser <AccountName>
addgroup friends
delgroup friends
usermod -g friends <Account>
usermod -g bob boby
usermod -aG friends bob
uname -a
cat /proc/cpuinfo
cat /proc/meminfo
free
ps -u yourusername
killall <processname>
top
echo $$
echo $!
kill -l
kill <PID>
ps -a
trap cmd sig1 sig2
trap "" sig1 sig2
trap - sig1 sig2
ps
ps aux --sort -rss
top
ps -e
killall UnResponsiveProg
Kill all processes matching the string "unresponsiveprog" (ignoring the difference between upper- ## lowercase letters)
killall -I unresponsiveprog
kill -9 <PID>
tload
htop
Ctrl + z
Then
bg
fg
date
uptime
cal
uptime
calendar
ex: 12-Mar-2004
date +%d-%b-%Y
today=$(date +%d-%b-%Y) && echo $today
If it's 9 am, then it will show 09
date โ+%Hโ
whereis app
which app
grep -P '("|/)\S+/\S+' setup.sh
sudo %program%
sudo program -l
sudo apt-get remove <application_name>
sudo apt-get install <nameOfSoftware>
ex
sudo apt-get install aptitude
sudo dpkg --install
ex
sudo dpkg --install megasync-xUbuntu_17.04_amd64.deb
(or bz2) - โCompiling from sourceโ
Step 1, create a folder to place the file:
mkdir /home/username/src <-- then cd to it
Step 2, with 'ls' verify that the file is there
(if not, mv ../file.tar.gz /home/username/src/)
Step 3, decompress the file (if .zip: unzip )
Step 4, use 'ls', you should see a new directory
Step 5, cd to the new directory
Step 6.1, use ls to verify you have an INSTALL file,
then: more INSTALL
If you don't have an INSTALL file:
Step 6.2, execute./configure <-- creates a makefile
Step 6.2.1, run make <-- builds application binaries
Step 6.2.2 : switch to root --> su
Step 6.2.3 : make install <-- installs the software
Step 7, read the readme file
./configure
make
make install
install a package (Debian)
dpkg -i pkg.deb
install a package (RPM)
rpm -Uvh pkg.rpm
sudo shutdown -h now
sudo shutdown -r now
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get update && sudo apt-get upgrade
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get autoremove
sudo apt autoremove && sudo apt clean
Alt + F2, type xkill
sudo ufw enable
sudo ufw disable
sudo apt install gufw
systemd-inhibit
systemd-inhibit myProgram
du -h
du -ah
du -sh
quota -v
du <filename>
du -s
df
du
The -h option makes the output easier to comprehend
du -h /etc
df -k
history
shopt -s histverify
!$
!*
!-n
!n
!<command>
!!
sudo !!
!!:s/<FROM>/<TO>/
!!:gs/<FROM>/<TO>/
!$:t
!$:h
Note: !! and !$ can be replaced with any valid expansion.
!!:n
!^
!$
!!:n-m
!!:n-$
!! can be replaced with any valid expansion i.e. !cat, !-2, !42, etc.
ctrl+r search_term
The default order for command lookup is functions, followed by built-ins, with scripts and executables last.
There are three built-ins that you can use to override this order: command
, builtin
and enable
.
removes alias and function lookup. Only built-ins and commands found in the search path are executed
command
builtin
enable
eval
cd; nano .bash_profile
alias gentlenode='ssh admin@gentlenode.com -p 3404' # add your alias in .bash_profile
Using alias to fix typos
alias gerp=grep
cd; nano .bashrc
shopt -s cdable_vars
export websites="/Users/mac/Documents/websites"
source .bashrc
cd websites
for i in *; do mv "$i" "
echo $i | sed "s/original name/new name/""; done
find ./ -type f -name *.url |xargs -I % cat % |cut -d= -f2-3 |grep ^pattern
Thanks a lot ! Very useful. You're missing the < month > part in the Crontab syntax ;-)