Linux good-to-know & shortcuts

New to Linux? or just can’t remember everything? bookmark this list ;)

FILE COMMANDS:

ls – directory listning
ls -al – formatted listing with hidden files
cd dir – change directory to dir
cd – change to home
pwd – show current directory
mkdir dir – create directory dir
rm file – delete file
rm -r dir – delete direcotry dir
rm -f file – force remove file
rm -rf dir – force delete directory dir
cp file1 file2 – copy file1 to file2
mv file1 file2 – move (rename?) file1 to file2
ln -s file link – create symbolic link ‘link’ to file
touch file – create or update file
cat > file – place standard input into file
more file – output the contents of the file
less file – output the contents of the file
head file – output first 10 lines of file
tail file – output last 10 lines of dile
tail -f file – output last lines of file as it grows

SSH:

ssh user@host – connect to host as user
ssh -p port user@host – connect using port
ssh -D port user@host – connect and create sock4/socks5 on port
ssh -N user@host – do not execute a remote command

INSTALLATION: (lol!)

./configure
make
make install

NETWORK:

ping host – ping host ‘host’
whois domain – get whois for domain
dig domain – get DNS for domain
dig -x host – reverse lookup host
wget file – download file
wget -c file – continue stopped download
wget -r url – recursively download files from url

SYSTEM INFO:

date – show current date/time
ntpdate dk.pool.ntp.org – sync time
cal – show this month’s calendar
uptime – show uptime
w – display who is online/logged in
whoami – who are you logged in as
uname -a – show kernel config
cat /proc/cpuinfo – cpu info
cat /proc/meminfo – memory information
man command – show manual for command
df – show disk usage
du – show directory space usage
du -sh – human readable size in gb
free – show memory and swap usage
whereis app – show possible locations of app
which app – show wich app will be run by default

SEARCHING:

find / -iname “*something*” – search in / for *something*
greb pattern files – search for pattern in files
greb -r pattern dir – search recursively for pattern in dir
command | grep pattern – search for pattern in the output of command
locate file – find all instances of file

PROCESS MANAGEMENT:

ps – display currently active processes
ps aux – ps with a lot of detail
kill pid – kill process with pid ‘pid’
killall proc – kill all processes names proc
bg – lists stopped/background jobs, resume stopped job in the background
fg – bring most recent job to foreground
fg n brings job n to foreground

FILE PERMISSIONS:

chmod octal file – change permission of file
4 – read (r)
2 – write (w)
1 – execute (x)

order: owner/group/everyone

eg:
chmod 777 – rwx for everyone
chmod 755 – rw for owner, rx for group/everyone

COMPRESSION:

tar -cf file.tar files – tar files into file.tar
tar -xf file.tar files – untar into current directory
tar -tf file.tar files – show contents of archive

tar flags:
c – create archive
t – table of contents
x- extract
f – specifies filename
z – use zip/gzip
j – bzip2 compression
k – do not overwrite
T – files from file
w – ask for confirmation
v -verbose

gzip file – compress file and rename to file.gz
gzip -d file.gz – decompress file.gz

SHORTCUTS:

ctrl+c – halts current command
ctrl+z -stops current command
ctrl+d – log out of current session
ctrl+w – erases one word in current line
ctrl+u – erases whole line
ctrl+r – reverse lookup of previous commands
!! – repeat last command
exit – log out

 

Leave a Reply