Difference between revisions of "Linux Commands"

From HyperSecurity Wiki
Jump to: navigation, search
Line 215: Line 215:
 
# Extract and reverse engineer .bin or .img files. Or any other binary:
 
# Extract and reverse engineer .bin or .img files. Or any other binary:
 
#*<pre>binwalk --dd='.*' file.bin</pre>
 
#*<pre>binwalk --dd='.*' file.bin</pre>
 +
# Extract compressed file system:
 +
#*<pre>7z e filename</pre>

Revision as of 00:35, 17 February 2020

  1. RPM Version Info:
    • rpm -qa foo
  2. Shutdown X11:
    • init 3
  3. Reboot the System:
    • init 6
  4. Mount a CDROM:
    • mount /dev/cdrom
  5. Unmount a CDROM:
    • umount /dev/cdrom
  6. List Start Up Scripts:
    • chkconfig --list
  7. Turn On Start Up Script:
    • chkconfig service start
  8. Turn Off Start Up Script:
    • chkconfig service off
  9. Get the kernel version by typing
    • uname -r
  10. Format USB Device to Vfat
    •  mkfs.vfat -F 32 /dev/sda1
  11. How to create tarball's assuming your directory is called foo:</pre>
    • tar -cvzf foo.tar.gz /dir/foo
  12. Add user to Virtual Postfix Database:</pre>
    • postmap virtual
  13. Enable RAID1 Mirroring ndas:
    • ndasadmin enable -s 1 -o w 2
  14. Reload Postfix:
    •  postfix reload
  15. Produces Postfix Queue List:
    •  postqueue -p
  16. Also Produces Postfix Queue List:
    • mailq
  17. Flush Postfix Queues:
    •  postqueue -f
  18. Remote Desktop for Windows (toggle -f on or off for fullscreen):
    • rdesktop -g 1152x768 -a 24 -b -f mail
  19. Unzip bz2 files:
    • bzip2 -cd files.tar.bz2 | tar xvf -
  20. Show program install path:
    • which {program}
  21. Removes mail from mail queue
    • postsuper -d {queue id}>
  22. Displays Hardware info from BIOS (must have installed dmidecode installed)
    • dmidecode
  23. To get a Network list of current IP/Hostname's, type the following on the command line:
    • dig axfr hosthame
  24. or to sort by IP type:
    • dig axfr hostname |grep IN | egrep A |sort -n  -k 5 -k 7 -t .
  25. Type the following to setup rpmq to find true kernel version
    • alias rpmq='rpm --qf '\''%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n'\'' -q'
  26. Type the following to determine the kernel version
    • rpmq kernel
  27. List all PCI Devices:
    • lspci
  28. Reload named:
    • rndc reload
  29. Create Database:
    • create database {DATABASE NAME};
  30. Create Database Privileges:
    • grant all privileges on {DATABASE NAME}.* to {DATABASE USER}@localhost identified by '{DATABASE PASSWORD}';
  31. Set Privileges:
    • flush privileges;
  32. Netstat IP,PORTS
    • netstat -tnap
  33. Create QEMU Disk Images:
    • qemu-img create -f qcow {name}.img 3G
  34. Install OS on QEMU Drive Image via CD-ROM
    • qemu -cdrom /dev/cdrom -hda {name}.img -m {memsize} -boot d
  35. Install OS on QEMU Drive Image via IMAGE
    • qemu -cdrom {name}.iso -hda {name}.img -m {memsize} -boot d
  36. Run QEMU Disk Images with Sound (Blaster16):
    • qemu -hda {name}.img -m {memsize} -soundhw es1370 -localtime
  37. Move seamless between host and guest
    • qemu -hda {name}.img -m {memsize} -soundhw es1370 -localtime -usb -usbdevice tablet
  38. Resize AVI Files (--export_asr 3 is widescreen and --export_asr 2 is fullscreen)
    • transcode -i INPUT.avi -y ffmpeg,ffmpeg -F mpeg4 -Z 320x,fast --export_asr 2 -o OUTPUT.avi -E 44100,16,2 -b 256
  39. Start NetworkManager GUI Applet
    • nm-applet &
  40. Set Password for MySQL Root
    • mysqladmin -u root password new-password
  41. Remove User account and Home dir
    • userdel -r {username}
  42. Mount an ISO image
    • mount -o loop -t iso9660 filename.iso /mnt/iso
  43. Create random passwords
    • head /dev/urandom | strings
  44. Show partions on a drive
    • sfdisk -l
  45. You want to download all the GIFs from an HTTP directory. The command doesn't work since HTTP retrieval does not support globbing. In that case, use:
    • wget -r -l1 --no-parent -A.gif http://host/dir/
  46. How to rsync
    • rsync -r -a -v -e "ssh -l {username}" --delete {remote machine}:/dir /dir
  47. How to check memory
    •  ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid
  48. How to search and replace recursively within files
    •  find . -type f -exec sed -i s/search/replace/g {} +
  49. How to convert Flac to MP3
    • for file in *.flac; do flac -cd "$file" | lame -h - "${file%.flac}.mp3"; done
  50. How to check 3ware Hardware RAID status:
    •  tw_cli /c0 show
  51. Dirvish Vault first init
    •  dirvish -vault ''vaultname'' --init
  52. CIFS mount:
    • mount -o username=username,password=1234,uid=username,gid=groupname,iocharset=utf8,file_mode=0777,dir_mode=0777,noperm //host/disk /mnt/NAS/
  53. How to install all development tools:
    • PRE Fedora 18: yum groups install "Development Tools"
    • POST Fedora 18: yum groupinstall development-libs development-tools gnome-software-development
    • apt-get install build-essential
  54. How to enable ndadmin slot:
    • ndasadmin enable -s 1 -o w
  55. How to install Debian Kernel headers:
    • apt-get install linux-headers-$(uname -r)
  56. How to find the largest file/directory human readable from your current directory:
    • du -hsx * | sort -rh | head -10
  57. How to list all installed PERL modules:
    • perl -MFile::Find=find -MFile::Spec::Functions -Tlwe  'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'
  58. GLOBAL REPLACE in the files (change call to mall in all *.kumac files):
    • awk '{gsub("call", "mall", $0); print > FILENAME}' *.kumac
  59. The fastest way to scan all your computers/network subnet for open ports ever:
    • nmap -T5 192.168.1.0/24
  60. Convert virtual image files:
    • ovftool --lax input.ovf output.vmx
  61. How to extract CPIO file:
    • cpio -id < filename
  62. How to remove all symbolic link:
    • find -type l -delete
  63. How to find device or partition block size:
    • blockdev --getbsz partition
  64. How to convert KVM to VMWARE:
    • qemu-img convert -O vmdk filename.qcow2 filename.vmdk
  65. List UUID of all disks:
    • ls /dev/disk/by-uuid -lt
  66. Add CDROM to apt:
    • apt-cdrom add
  67. Rebuild software RAID:
    • mdadm --assemble --scan
  68. Time stamp on history command:
    • HISTTIMEFORMAT="%d/%m/%y %T " && history<pre>
  69. Remount read/write:
    • mount -o remount, rw / 
  70. Find port number of running application:
    • lsof -Pan -p {PID} -i
  71. WAN IP Address from commandline:
    • curl -s ifconfig.co
  72. Burn CD/DVD commandline:
    • growisofs -dvd-compat -Z /dev/cdrom=filename.iso
  73. Bandwidth Test Commandline:
    • curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
  74. Fix E353: Nothing in register "
    • echo set clipboard=unnamed >> ~/.vimrc
  75. Find Out Which Process Is Listening Upon a Port:
    • netstat -tulpn
  76. Replace all spaces in files within a directory with an underscore:
    • for f in *\ *; do mv "$f" "${f// /_}"; done
  77. Disk usage of all directories including hidden:
    • du -sch .[!.]* *
  78. Check process by CPU and PID:
    • ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
  79. Create simple HTTP server from present working directory:
    • python -m SimpleHTTPServer
  80. Resize img file
    • qemu-img resize test.img 2G
  81. a wk vertical to horizontal
    • awk 'ORS=" "' filename
  82. Re-read partition table after modifications (SD or USB):
    • partprobe /dev/sdX
  83. Find with max depth of 3 directories:
    • find -maxdepth 3
  84. Find SCSI/SATA devices
    • lsscsi
  85. ecm uncompress multiple files:
    • for i in *; do  ecm-uncompress "$i"; done
  86. Force downgrade of package:
    • apt-get install apt=1.4.8 libapt-pkg5.0=1.4.8 apt-utils=1.4.8 libapt-inst2.0:amd64=1.4.8
  87. Find package dependencies from repo:
    • debfoster -d package
  88. List video drivers used. Search for "configuration":
    • dlshw -c video
  89. List all listening network ports:
    • netstat -ntpl
  90. Check ports using netcat:
    • nc -w 5 -zv {ipaddress} {port}
  91. Show Debian/Ubuntu release information:
    • lsb_release  -a
  92. Reinstall GRUB on drives after OS is running:
    • dpkg-reconfigure grub-pc
  93. Cut example to get full names of users from passwd:
    • cut -d':' -f5 /etc/passwd
  94. Deletes any trailing whitespace at the end of each line:
    • :%s/\s\+$//e
  95. Check UDP port is open/closed:
    • map -sU -p port ip
  96. Unlink all symbolic links in dir:
    • find . -type l -exec unlink {} \;
  97. See process in memory:
    • ps wwu -C process
  98. See process tree of all processes on system:
    • ps axjf
  99. Sort processes memory from highest to lowest:
    • ps -o pid,user,%mem,command axf | sort -b -k3 -r
  100. Sort processes CPU from highest to lowest:
    • ps -o pid,user,%cpu,command axf | sort -b -k3 -r
  101. Display uncommented lines in a file:
    • cat {filename} | egrep -v "(^#.*|^$)"
  102. List all process running on port number
    • lsof -i :8080
  103. Show the time and date when Linux was first installed
    • ls -lact --full-time /etc |tail
  104. Show SSL Cert information
    • curl --insecure -v https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }'
  105. Find largest files by size
    • sudo find / -xdev  -type f -size +100M -exec ls -hla {} \; | sort -nk 5
  106. Display SSL Cert expiry date.
    • openssl x509 -enddate -noout -in file.pem
  107. Extract and reverse engineer .bin or .img files. Or any other binary:
    • binwalk --dd='.*' file.bin
  108. Extract compressed file system:
    • 7z e filename