Power Linux Commands

Find Command

  • find -iname '*.jsp' | xargs grep -i 'hello'
  • find . -mtime -3 # only those modified three or fewer days ago
  • find . -mmin -60 # modified last 60 min
  • find . -atime -3 # only those accessed three or fewer days ago
  • find . -amin -60 # accessedlast 60 min
  • find / -name core -exec /bin/rm -f '{}' \; # same thing
  • find -iname "MyCProgram.c" -exec md5sum {} \;
  • find ~ -empty
  • find . -type d # find only dir
  • find . -type f # find only normal file
  • find . -type f -name ".*" # find hidden file
  • find ~ -size +100M # more then 100M
  • find -name "*.txt" 2»/dev/null # redirecting errors to null
  • find . -type f -exec ls -s {} \; | sort -n -r | head -5 # top big file, remove -r for top small file
  • find ./ -type d -name ".svn" -exec rm -rf {} \;
  • locate filename

File related Command

  • touch hello.txt
  • cat input.txt
  • mkdir dir
  • mkdir -p dir/dir1/dir2 # create recursive directory
  • rm -rf dir1/
  • rm hello.txt
  • shred -vfz -n 10 fileName # v:verbose, f:forcefully, z:fill with zero, n: iteration; overwrite file with randomize bit, last one with zero.
  • cp file.txt /tmp
  • cp -r dir /tmp
  • cp -p file1 file2 # preserving the mode, ownership and timestamp
  • scp dir 001.1.861.291|doomhamm#001.1.861.291|doomhamm:~/
  • mv dir /tmp/
  • diff -w name_list.txt name_list_new.txt # diff without whitespace
  • >/tmp/a.txt # make file empty
  • ln -s /usr/jdk1.7 /usr/java
  • sudo chmod 777 a.txt # rwxrwxrwx, owner, group, others
  • sudo chmod -R 700 dir1/
  • sudo chgrp new_group someFile
  • sudo chown newUser someFile
  • file fileName # determine file type
  • stat fileName # detail about a file
  • split —bytes=1G /media/Useless/Debian.vdi /media/Useless/DebianVDI_ # split file
  • cat /media/Useless/DebianVDI_* > /media/Useless/Debian.vdi # join file

Compression Command

  • bz2:
    • tar -jcvf books.tar.bz2 Books/
    • tar -jxvf books.tar.bz2
  • tar:
    • tar -cvf books.tar Books/
    • tar -xvf books.tar
  • zip:
    • zip -9r books.zip Books/
    • unzip books.zip
  • gzip:
    • gzip test.txt
    • gzip -d test.txt.gz

Archive Command

  • ls | cpio -ov > myArch.cpio # copy all file to myArch.cpio
  • cpio -iv < myArch.cpio # extract myArch.cpio
  • cpio -it -F myArch.cpio # view content

Basic Command

  • ls -lah
  • ls -all
  • ls -lt # order files based on last modified time
  • ls -a # show hidden file
  • pwd # Print working directory
  • cd - # switching between last dirs
  • less fileName # view readonly file, ctrl-f for forward, ctrl-b for backward, / for search
  • head -5 fileName # show first 5 line
  • tail -5 fileName # show last 5 line
  • tail -f fileName # editable buffer
  • alias {name} '{command}'

Reload Script Command

  • source /etc/profile

Disk related Command

  • df -hT # h for human readble, T for device type
  • du -sh # file space usage for a given directory
  • sudo fdisk -l # list partition table

Process related Command

  • top -u userName # see user process
  • ps -ef | grep firefox
  • kill -9 1986
  • killall -9 firefox
  • pstree -p
  • pstree <userName>
  • ./my-script.sh & # run script in background
  • nohup ./my-script.sh & # run script in background even user logout or ssh session broke
  • at -f my.sh 22:59 02252013 # schedule a script at 22:59 Feb.25, 2013
  • at -l # list schedule job
  • atrm 10 # delete schedule job no. 10

Remote login Command

  • ssh 001.1.861.291|doomhamm#001.1.861.291|doomhamm
  • ssh -p port user@host
  • Conf. file: # vi /etc/ssh/sshd_config

Networking Command

  • ping 192.168.1.1
  • netstat -ntlp
  • ifconfig # only active network interface
  • ifconfig -a # all network interface
  • iwconfig # wireless network interface
  • ifup eth0
  • ifdown eth0
  • /etc/init.d/networking restart

Export Command

  • export | grep JAVA # view java related environment variables
  • export JAVA_HOME=/usr/java

System Command

  • uname -a # system info
  • whereis ls
  • whatis ls
  • who -a # who is currently logged in the system
  • cat /proc/meminfo
  • cat /proc/cpuinfo
  • uptime
  • which app # show which app will be run by default
  • sudo passwd root # set password for root, root will be enabled
  • finger mmahmood # view detail about a particular user
  • lsb_release -a # distribution number

Device Command

  • lspci
  • lshw
  • sudo dmidecode
  • sudo dmidecode -s system-product-name # i.e. Satellite L635
  • sudo dmidecode -t system
  • sudo dmidecode -t 16 # maximum RAM supported by the system

Create ISO

  • sudo cat /dev/scd0 > /home/mmahmoud/Desktop/ubuntu.iso # from CD
  • mkisofs -o /home/mmahmoud/Desktop/avast.iso /media/CODER/ # from directory

Module (Hardware Driver)

  • modprobe -l # list all Module, use ‘grep’
  • modprobe driver_name.ko # Load Module
  • add in /etc/modules # Load Module on Boot

Install Packages

  • ./configure;make;make install
  • sudo dpkg -i —force-depends *.deb # Install with dependency
  • sudo apt-get install <package_name>
  • sudo apt-get install -f <package_name>
  • sudo apt-get build-dep <package_name>
  • sudo apt-get remove <package_name>
  • sudo apt-cache search <search_term>

Service Command

  • Try using sysv-rc-conf by
    • sudo apt-get install sysv-rc-conf
    • sudo sysv-rc-conf
  • service —status-all
  • sudo service {service-name} restart
  • sudo service {service-name} stop
  • sudo service {service-name} start

Shutdown/Reboot Command

  • shutdown -h now # shutdown now
  • shutdown -h 18:00 # shutdown at 6PM
  • shutdown -r now # reboot now
  • shutdown -c # cancel running shutdown

Miscellaneous Command

  • wall (type msg, crtl+d to send )# sends a message to everybody logged in with their mesg(1) permission set to yes.

Cron Job Command

  • watch -n1 command

Encryption/Decryption Command

  • openssl aes-128-cbc -salt -in myFile -out myFileEnc # encrypt file
  • openssl aes-128-cbc -salt -d -in myFileEnc -out myFile # decrypt file

User Administration Command

  • useradd -d /home/mmahmood -m mmahmood
  • cat /etc/passwd # show user list
  • userdel mmahmood # delete user
  • userdel -r mmahmood # delete user with home directory

Remote directory mount

sshfs moc.revres.etomer|emanresUhss#moc.revres.etomer|emanresUhss:/nfs/multimedia/dn5-test /nfs/multimedia/dn5-test

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License