Linux commands


  • sudo bash -c “echo ‘user ALL=(ALL) NOPASSWD: ALL’ > /etc/sudoers.d/user
  • sudo -i                    (Sudo to root)
  • sudo su user          (Sudo to user which don’t have password)
  • su – root OR su –    (Switch to root)
  • su user OR su – user
  • sudo ls -l /etc/

Shutdown and Reboot:

  • poweroff , shutdown -h now
  • reboot, shutdown -r now

Copy, Move, Delete:

  • cp srcfile destfile
  • cp -r ./dir /tmp          (Copy dir into /tmp directory)
  • mv file1 file2; mv dir1 dir2  (Rename file or dir)
  • mv file /tmp; mv dir /tmp    (Move file or dir into /tmp)
  • rm file; rm *.txt; rm -rf dir
  • rmdir dir

SCP commands:

  • scp file root@host:/tmp                  (Copy file onto remote host)
  • scp -r dir root@host:/tmp               (Copy dir onto remote host)
  • scp root@host:/tmp/file /tmp/         (Copy file from host to localhost)
  • scp -r root@host:/tmp/dir/ /tmp/   (Copy dir from host to localhost)

SSH commands:

  • ssh user@host; ssh -l user host
  • ssh -i ~/.ssh/id_rsa user@host
  • ssh-keygen                 (Generate Public and Private key)
    • $HOME/.ssh/
    • id_rsa: private key; public key; authorized_keys: public keys list
    • known_hosts: Hosts list to allow login; config:  config file

Disk Partitions:

  • lsblk; blkid; parted -l; cat /proc/partitions
  • fdisk -l /dev/sda; parted /dev/sda print
  • partprobe -s  /dev/sda (Reload partition table)
  • mkfs -t ext4|xfs imgfile | /dev/sda1
  • fsck
  • dumpe2fs /dev/sda1
  • tune2fs -l /dev/sda1; tune2fs -i|-c|-m 10 /dev/sdb1
  • xfsdump; xfsrestore; xfs-freeze
  • e4defrag -c /dev/sdb1; e4defrag /var/log
  • dd if=/dev/sda of=mbrbkup bs=512 count=1   (Backup MBR)
  • dd if=mbrbkup of=/dev/sda bs=512 count=1   (Restore MBR)

mount and umount:

  • mount       -> /proc/mounts
  • mount -a   ->  /etc/fstab
  • mount -o remount /dev/sdb1 -> /etc/fstab:/etc/sdb1
  • mount /dev/sdb1 /mnt; mount /imgfile /mnt
  • umount /mnt; umount /dev/sda; umount /imgfile
  • mount -o loop /dev/loop1 /mnt/loop
  • mount -o ro,noexec /imgfile /mnt
  • mount -t tmpfs -o size=1G none /mnt/tmpfs
  • mount -t tmpfs -o size=200M tmpfs /mnt/tmpfs
  • /etc/fstab   /dev/sda1   /mnt   ext4   default   0   0
  • /etc/fstab   /imgfile      /mnt   ext4    loop       0   0

Filesystem / Disk Usage:

  • df -hT        (Show disk usage and filesystem mount)
  • du -csh /tmp/*      (Show size of /tmp directory)
  • du -hxd 1 /;  du -cshx /* -exclude=proc (Show size of / directories)

/proc/ options:

  • ls -al /proc/ | grep ^[-] | sort
  • cat /proc/meminfo; free -mh
  • cat /proc/swpas; free -mh
  • cat /proc/partitions
  • cat /proc/cpuinfo
  • cat /proc/mounts
  • cat /proc/version
  • cat /proc/filesystems

Configure Kernel parameters at runtime:

  • sysctl -a; sysctl -a | grep pid_max
  • sysctl kernel.pid_max; cat /proc/sys/kernel/pid_max
  • sysctl kernel.pid_max=30000; echo 3000 > /proc/sys/kernel/pid_max
  • sysctl -p /etc/sysctl.conf
  • sysctl –system -> /etc/sysctl.d/99-sysctl.conf

List, Add or Remove modules from Kernel:

  • lsmod
  • modinfo dummy
  • modprobe module; insmod /tmp/module.ko
  • modprobe -r module; rmmod module
  • depmod
  • /lib/modules/$(uname –r)/; /etc/modprobe.d/*.conf

at and crontab:

  • at  (Press ctr+d when done adding the job)
    • at now + 5 minutes|hours|days|weeks|months|years 
    • at -f 2:30 PM 10/21/2017
    • atq             (List jobs)
    • atrr  id      (Remove jobs)
  • crontab  [*mins(0-59)   *hrs(0-23)   *day(1-31)   *mon(1-12)    *dayofweek(0-6)]
    • crontab -l; crontab -r; crontab -e
    • crontab -u user -l | -e
    • crontab
    • @reboot, @hourly, @daily, @weekly, @monthly, @yearly
    • 0 5,17 * * * $HOME/         (Daily at 5 am and 5 pm)
    • */10 * * * * $HOME/         (every 10 mins)
    • * */4 * * *   $HOME/         (every 4 hours)
    • cat /etc/crontab; /etc/cron.d
    • More examples:

P.S. at command scheduled jobs only once, whereas crontab is used for running the jobs repeatedly.

Miscellaneous commands:

  • dmesg    -w        (read kernel messages)
  • echo $0; ps -p “$$”   (Prints current shell)
  • echo $SHELL             (Prints default  shell)
  • head -fn1000 /var/log/messages; ps -ef | head
  • less /var/log/messages; ps -ef | less
  • lsmod             (Show status of modules in Kernel)
  • nice -n 10 bash  
  • renice -n 15 -p 1234; ps -o ni,pid,cmd,pri  (Change nice value of a process ) 
  • time                (calculate time of a command)
  • tail -fn1000 /var/log/messagesps -ef | tail
  • udev-> /etc/udev/udev.conf; /etc/udev/rules.d/*.rules; /usr/lib/udev/rules.d/*.rules
  • uname -a | -r  (Prints system information)
  • watch  date   (Runs a command repeatedly)
  • which bash    (Shows the full path of command      
  • whoami          (Shows effective or currently login userid)
  • ./configure; make; make install    (Install from source)

Log files:

  • /var/log/messages  (Global system messages)
  • /var/log/dmesg        (Kernel ring buffer messages)
  • /var/log/secure        (Authentication and authorization messages)
  • /var/log/cron            (Cron jobs messages)
  • /var/log/boot.log     (System boot messages)
  • /var/log/yum.log
  • /var/log/firewalld
  • /var/log/httpd/access_log; /var/log/httpd/error_log
  • /var/log/audit/audit.log

About Ishtiaque

I am IBM Certified Infrastructure Systems Architect, TOGAF 9 Certified, ITIL V3 Foundation certified and Oracle Certified Export in Java Web Component Developer with over 10 years of support and development experience in IBM middleware software and Java. Additionally, have a sound grip in databases, Linux and OpenStack administration. I hold the following certifications: IBM Certified Infrastructure Systems Architect TOGAF 9 Certified Oracle Certified Expert, Java EE6 Web Component Developer Oracle Certified Professional – Java 6 Programmer ITIL v3 Foundation Certified IBM Certified Solution Architect – Cloud Computing Infrastructure V1 IBM Certified System Administrator – WebSphere Portal V8, V7, V6.1, V6 IBM Certified System Administrator – WebSphere Application Server V7, V6.1 IBM Certified System Administrator – AIX V7 IBM Certified System Administrator – WebSphere MQ V7 IBM Certified Deployment Professional – Business Process Manager Advanced V7.5 IBM Certified Solution Advisor – Cloud Computing Architecture V3 IBM Certified Solution Developer – WebSphere Portal V5.1
This entry was posted in LFCS, Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s