Skip to content

Shell

What version of the system ?

cat /etc/issue
cat /etc/*-release
cat /etc/lsb-release
cat /etc/redhat-release

What is its kernel version ?

cat /proc/version
uname -a
uname -mrs
rpm -q kernel
dmesg | grep Linux
ls /boot | grep vmlinuz

What is the environment variables ?

cat /etc/profile
cat /etc/bashrc
cat ~/.bash_profile
cat ~/.bashrc
cat ~/.bash_logout
env
set

Service settings, there is any wrong allocation?

cat /etc/syslog.conf
cat /etc/chttp.conf
cat /etc/lighttpd.conf
cat /etc/cups/cupsd.conf
cat /etc/inetd.conf
cat /etc/apache2/apache2.conf
cat /etc/my.conf
cat /etc/httpd/conf/httpd.conf
cat /opt/lampp/etc/httpd.conf
ls -aRl /etc/ | awk ‘$1 ~ /^.*r.*/

Other users host communication with the system ?

lsof -i
lsof -i :80
grep 80 /etc/services
netstat -antup
netstat -antpx
netstat -tulpn
chkconfig --list
chkconfig --list | grep 3:on
last
lastlog

User Info

id
whoami

Users

users
cat /etc/passwd
cat /etc/passwd | cut -d: -f1

Groups

groups
cat /etc/group
cat /etc/group | cut -d: -f1

Find all files by groups

find / -group <group-name>

Find all files by groups (executable)

find / -executable -group <group-name>

System info

uname
hostname
cat /etc/os-release

Kernel version

uname -r
cat /proc/version

Network

ifconfig
  • pwd - Print working directory
  • cd - Change directory
  • cd ~ - Change directory to your home directory

Documentation

  • man
  • man -k

Looking at files

  • ls - List files in directory
  • ls -ltr - Sort list by last modified. -time -reverse
  • ls -l
  • ls -l1
  • ls -la

File

  • file - Show info about file. What type of file it is. If it is a binary or text file for example.
  • touch file.txt - Create a new file
  • vim file.txt - Open new file in vim
  • echo "lorem-ipsum" > file.txt" - overwrite(or create new) file with string from echo
  • echo "lorem-ipsum" >> file.txt" - append(or create new) file with string from echo

File Read

  • cat - Output content of file.
  • less - Output file but just little bit at a time. Use this one. Not more.
  • more - Output file but just little bit at a time. less is better.
  • rm - Remove file
  • tail - Print the last 10 lines of each FILE to standard output

Directory

  • mkdir some_direcotry - Make directory
  • mkdir -p some_direcotry/next_one/one_more - Make entire directory structure
  • rm -rf - Remove recursively directory and its content
  • tree -h - List all files as tree
# find - This will send all permissions denied outputs to dev/null.
# find - is slower than locate but a lot more thorough. You can search for files recursively and with regex and a lot of other features.
find / -name file 2>/dev/null
# locate  - is really fast because it relies on an internal database. So in order to have it updated you need to run:
# locate  - Then you can easily find stuff like this:
sudo updatedb
locate filename
# which - Outputs the path of the binary that you are looking for. It searches through the directories that are defined in your $PATH variable.
which bash

Filters

There are certain programs that are especially useful to use together with pipes. They can also be used as stand-alone programs but you will often see them together with pipes.

sort
uniq
grep
head
tail
tr

Service

sudo systemctl start apache2
sudo systemctl status apache2
sudo systemctl restart apache2
sudo systemctl stop apache2
sudo systemctl enable apache2 # autostart on boot time
systemctl list-unit-files # list all services

History

history # show history
! <id>  # select item from history

Grep

cat /etc/passwd | grep 'root'

Edit/Replace

echo "I am Mr.Cat" | sed 's/Cat/Robot/'

Cut

echo "root,lorem,password123,ipsum,/root" | cut -d"," -f1,3,5
# root,password123,/root

Awk

cat /etc/passwd | awk -F: '{printf "USER--> %s\t HOME--> %s\n", $1, $6}'

Piping

cat /etc/passwd | grep '/bin/false' | cut -d":" -f 1,6  | awk -F: '{printf "user: %s home:%s\n", $1, $2}'
cat /etc/passwd | grep '/bin/false' | awk -F: '{printf "user: %s home:%s\n", $1, $6}'

File editor

vi
vim
nano

Compare files

comm
diff
vimdiff

Monitoring

watch

Downloading Files

wget
curl
axel

Sudo

  • sudo -l - List what rights the sudo user has.

References