Difference between revisions of "Linux Commands"

From HyperSecurity Wiki
Jump to: navigation, search
 
(79 intermediate revisions by 7 users not shown)
Line 21: Line 21:
 
#How to create tarball's assuming your directory is called foo:</pre>
 
#How to create tarball's assuming your directory is called foo:</pre>
 
#*<pre>tar -cvzf foo.tar.gz /dir/foo</pre>
 
#*<pre>tar -cvzf foo.tar.gz /dir/foo</pre>
#Add user to Virtual Postfix Database:</pre>
+
#Add user to Virtual Postfix Database:
 
#*<pre>postmap virtual</pre>
 
#*<pre>postmap virtual</pre>
 
#Enable RAID1 Mirroring ndas:
 
#Enable RAID1 Mirroring ndas:
Line 33: Line 33:
 
#Flush Postfix Queues:
 
#Flush Postfix Queues:
 
#*<pre> postqueue -f</pre>
 
#*<pre> postqueue -f</pre>
 +
#Read all postfix config:
 +
#*<pre>postconf</pre>
 
#Remote Desktop for Windows (toggle -f on or off for fullscreen):
 
#Remote Desktop for Windows (toggle -f on or off for fullscreen):
 
#*<pre>rdesktop -g 1152x768 -a 24 -b -f mail</pre>
 
#*<pre>rdesktop -g 1152x768 -a 24 -b -f mail</pre>
Line 61: Line 63:
 
#Set Privileges:
 
#Set Privileges:
 
#*<pre>flush privileges;</pre>
 
#*<pre>flush privileges;</pre>
#Netstat IP,PORTS
+
#Netstat TCP/UDP IP,PORTS
#*<pre>netstat -tnap</pre>
+
#*<pre>netstat -tunlp</pre>
 
#Create QEMU Disk Images:
 
#Create QEMU Disk Images:
 
#*<pre>qemu-img create -f qcow {name}.img 3G</pre>
 
#*<pre>qemu-img create -f qcow {name}.img 3G</pre>
Line 123: Line 125:
 
# How to extract CPIO file:
 
# How to extract CPIO file:
 
#*<pre>cpio -id < filename</pre>
 
#*<pre>cpio -id < filename</pre>
# How to create a CPIO file:
+
# How to remove all symbolic link:
#*<pre>find . | cpio --create --format='filename' > /tmp/newinitrd</pre>
+
#*<pre>find -type l -delete</pre>
# How to all kernel mods:
+
# How to find device or partition block size:
#*<pre>find /lib/modules/*/ -type f -iname '*.ko' | less</pre>
+
#*<pre>blockdev --getbsz partition</pre>
# Find binaries only in a directory:
+
# How to convert KVM to VMWARE:
#*<pre>find -type f -executable -exec sh -c 'test "$(head -c 2 "$1")" != "#!"' sh {} \; -print</pre>
+
#*<pre>qemu-img convert -O vmdk filename.qcow2 filename.vmdk</pre>
# Convert VMware to KVM:
+
# List UUID of all disks:
#*<pre>qemu-img convert -O vmwareImage.vmdk kvmImage.qcow2</pre>
+
#*<pre>ls /dev/disk/by-uuid -lt</pre>
# How to replace space with new line:
+
# Add CDROM to apt:
#*<pre>'tr ' ' '\n' < fileName</pre>
+
#*<pre>apt-cdrom add</pre>
# How to reinstall GRUB2 Debian:
+
# Rebuild software RAID:
#*<pre>apt-get install --reinstall grub2-efi-amd64</pre>
+
#*<pre>mdadm --assemble --scan</pre>
# How to change or modify SSH-Key pass phrase:
+
# Time stamp on history command:
#*<pre>ssh-keygen -p -f keyfile</pre>
+
#*<pre>HISTTIMEFORMAT="%d/%m/%y %T " && history<pre></pre>
# How find parition block size:
+
# Remount read/write:
#*<pre>blockdev --getbsz /dev/partion</pre>
+
#*<pre>mount -o remount, rw / </pre>
# How to fix inssev warning when trying to use chkconfig:
+
# Find port number of running application:
#*<pre>update-rc.d -f <deamon> remove</pre>
+
#*<pre>lsof -Pan -p {PID} -i</pre>
#*<pre>update-rc.d -f <deamon> defaults</pre>
+
# WAN IP Address from commandline:
# How to turn on/off DNS trace logging:
+
#*<pre>curl -s ifconfig.co</pre>
#*<pre>rndc querylog</pre>
+
# Burn CD/DVD commandline:
# Commandline speed test:
+
#*<pre>growisofs -dvd-compat -Z /dev/cdrom=filename.iso</pre>
#*<pre>wget -O /dev/null http://speedtest.tele2.net/1GB.zip</pre>
+
# Bandwidth Test Commandline:
# Burn ISO or other images from commandline:
+
#*<pre>curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -</pre>
#*<pre>growisofs -Z /dev/cdrom=file.iso</pre>
+
# Fix E353: Nothing in register "
# Remove white space in all files in directory
+
#*<pre>echo set clipboard=unnamed >> ~/.vimrc</pre>
#*<pre>for file in *; do mv "$file" "${file//[[:space:]]}"; done</pre>
+
# Find Out Which Process Is Listening Upon a Port:
# How to get UDID from iPhone:
+
#*<pre>netstat -tulpn</pre>
#*<pre>lsusb -s :`lsusb | grep iPhone | cut -d ' ' -f 4 | sed 's/://'` -v | grep iSerial | awk '{print $3}'</pre>
+
# Replace all spaces in files within a directory with an underscore:
# How to remount read only drive live:
+
#*<pre>for f in *\ *; do mv "$f" "${f// /_}"; done</pre>
#*<pre>mount / -rw -o remount</pre>
+
# Disk usage of all directories including hidden:
# How to sniff TFTP/DHCP requests:
+
#*<pre>du -sch .[!.]* *</pre>
#*<pre>tshark -i eth0 -f "tcp portrange 67-69" -V</pre>
+
# Check process by CPU and PID:
# Fix Debian keyring on the commandline:
+
#*<pre>ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10</pre>
#*<pre>apt-get install debian-keyring debian-archive-keyring</pre>
+
# Create simple HTTP server from present working directory:
#*<pre>apt-key update</pre>
+
#*<pre>python -m SimpleHTTPServer</pre>
# Test HDD read/write speeds:
+
# Resize img file
#*<pre>hdparm -Tt /dev/sda</pre>
+
#*<pre>qemu-img resize test.img 2G</pre>
# Kill all processes with pgrep
+
#a wk vertical to horizontal
#*<pre>kill $(pgrep name)</pre>
+
#*<pre>awk 'ORS=" "' filename</pre>
# Force user to change password in x amount of days:
+
# Re-read partition table after modifications (SD or USB):
#*<pre>chage -d {days} {username}</pre>
+
#*<pre>partprobe /dev/sdX</pre>
# Change automatically expire user accounts in x amount of days:
+
# Find with max depth of 3 directories:
#*<pre>usermod --expiredate={2015-06-01} {username}</pre>
+
#*<pre>find -maxdepth 3</pre>
# Install KDE on Fedora Systems:
+
# Find SCSI/SATA devices
#*<pre>yum groupinstall "KDE Plasma Workspaces:"</pre>
+
#*<pre>lsscsi</pre>
#*<pre>dnf install @kde-desktop"</pre>
+
# ecm uncompress multiple files:
# Search for lines that do not match #. The first ^ refers to the beginning of the line. [^#;] means any character which is not # or ;
+
#*<pre>for i in *; do  ecm-uncompress "$i"; done</pre>
#*<pre>grep "^[^#;]" filename</pre>
+
# Force downgrade of package:
# Match two patterns using grep:
+
#*<pre>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</pre>
#*<pre>grep -E "string1|string2" filename</pre>
+
# Find package dependencies from repo:
# Disable baloo service:
+
#*<pre>debfoster -d package</pre>
#*<pre>balooctl disable</pre>
+
# List video drivers used. Search for "configuration":
# Monitor kernel messages
+
#*<pre>dlshw -c video</pre>
#*<pre>udevadm monitor --kernel<pre></pre>
+
# List all listening network ports:
 +
#*<pre>netstat -ntpl</pre>
 +
# Check TCP ports using netcat:
 +
#*<pre>nc -w 5 -zv {ipaddress} {port}</pre>
 +
# Check UPD ports using netcat:
 +
#*<pre> nc -u -w 5 -zv {ipaddress} {port}</pre>
 +
# Show Debian/Ubuntu release information:
 +
#*<pre>lsb_release  -a</pre>
 +
# Reinstall GRUB on drives after OS is running:
 +
#*<pre>dpkg-reconfigure grub-pc</pre>
 +
# Cut example to get full names of users from passwd:
 +
#*<pre>cut -d':' -f5 /etc/passwd</pre>
 +
# Deletes any trailing whitespace at the end of each line:
 +
#*<pre>:%s/\s\+$//e</pre>
 +
# Check UDP port is open/closed:
 +
#*<pre>map -sU -p port ip</pre>
 +
# Unlink all symbolic links in dir:
 +
#*<pre>find . -type l -exec unlink {} \;</pre>
 +
# See process in memory:
 +
#*<pre>ps wwu -C process</pre>
 +
# See process tree of all processes on system:
 +
#*<pre>ps axjf</pre>
 +
# Sort processes memory from highest to lowest:
 +
#*<pre>ps -o pid,user,%mem,command axf | sort -b -k3 -r</pre>
 +
# Sort processes CPU from highest to lowest:
 +
#*<pre>ps -o pid,user,%cpu,command axf | sort -b -k3 -r</pre>
 +
# Display uncommented lines in a file:
 +
#*<pre>cat {filename} | egrep -v "(^#.*|^$)"</pre>
 +
# List all process running on port number
 +
#*<pre>lsof -i :8080</pre>
 +
# Show the time and date when Linux was first installed
 +
#*<pre>ls -lact --full-time /etc |tail</pre>
 +
# Show SSL Cert information
 +
#*<pre>curl --insecure -v https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }'</pre>
 +
# Find largest files by size
 +
#*<pre>sudo find / -xdev  -type f -size +100M -exec ls -hla {} \; | sort -nk 5</pre>
 +
# Display SSL Cert expiry date.
 +
#*<pre>openssl x509 -enddate -noout -in file.pem</pre>
 +
# Extract and reverse engineer .bin or .img files. Or any other binary:
 +
#*<pre>binwalk --dd='.*' file.bin</pre>
 +
# Extract compressed file system:
 +
#*<pre>7z x filename</pre>
 +
# Unzip multiple files with spaces in name:
 +
#*<pre>find . -name "*.zip" -exec sh -c 'unzip -n "{}" | head -n 7' \;</pre>
 +
# Remove files past a certain day (Example 5 is five days):
 +
#*<pre>find /path/to/files/* -mtime +5 -exec rm {} \;</pre>
 +
# You can use the command below to probe the port 22:
 +
#*<pre>sudo lsof -i :22</pre>
 +
# Print history without line numbers or date:
 +
#*<pre>fc -l -n 1 | sed 's/^\s*//'</pre>
 +
# Set the "immutable" attribute to make a file non-writable:
 +
#*<pre>chattr +i {filename}</pre>
 +
# Set the "unimmutable" attribute to make a file writable:
 +
#*<pre>chattr -i {filename}</pre>
 +
# Check webserver a host is using:
 +
#*<pre> wget -q -O- --save-headers domainname.com | grep '^[Ss]erver:' | awk '{print $2}'</pre>
 +
# Look at errors in specific services in systemd:
 +
#*<pre>journalctl -xe -u {service name}</pre>
 +
# Convert vertical text to horizontal:
 +
#*<pre>tr '\n' ' ' <file.txt</pre>
 +
# Find and sort files by disk space
 +
#*<pre>du -sch $(ls -A) 2> /dev/null | sort -rh</pre>
 +
# Find files that uses port 443
 +
#*<pre>lsof -i :443</pre>
 +
# Find which directory has the most files:
 +
#*<pre>find . -type d | cut -d/ -f 2 | uniq -c</pre>

Latest revision as of 04:44, 12 October 2023

  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:
    • 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. Read all postfix config:
    • postconf
  19. Remote Desktop for Windows (toggle -f on or off for fullscreen):
    • rdesktop -g 1152x768 -a 24 -b -f mail
  20. Unzip bz2 files:
    • bzip2 -cd files.tar.bz2 | tar xvf -
  21. Show program install path:
    • which {program}
  22. Removes mail from mail queue
    • postsuper -d {queue id}>
  23. Displays Hardware info from BIOS (must have installed dmidecode installed)
    • dmidecode
  24. To get a Network list of current IP/Hostname's, type the following on the command line:
    • dig axfr hosthame
  25. or to sort by IP type:
    • dig axfr hostname |grep IN | egrep A |sort -n  -k 5 -k 7 -t .
  26. Type the following to setup rpmq to find true kernel version
    • alias rpmq='rpm --qf '\''%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n'\'' -q'
  27. Type the following to determine the kernel version
    • rpmq kernel
  28. List all PCI Devices:
    • lspci
  29. Reload named:
    • rndc reload
  30. Create Database:
    • create database {DATABASE NAME};
  31. Create Database Privileges:
    • grant all privileges on {DATABASE NAME}.* to {DATABASE USER}@localhost identified by '{DATABASE PASSWORD}';
  32. Set Privileges:
    • flush privileges;
  33. Netstat TCP/UDP IP,PORTS
    • netstat -tunlp
  34. Create QEMU Disk Images:
    • qemu-img create -f qcow {name}.img 3G
  35. Install OS on QEMU Drive Image via CD-ROM
    • qemu -cdrom /dev/cdrom -hda {name}.img -m {memsize} -boot d
  36. Install OS on QEMU Drive Image via IMAGE
    • qemu -cdrom {name}.iso -hda {name}.img -m {memsize} -boot d
  37. Run QEMU Disk Images with Sound (Blaster16):
    • qemu -hda {name}.img -m {memsize} -soundhw es1370 -localtime
  38. Move seamless between host and guest
    • qemu -hda {name}.img -m {memsize} -soundhw es1370 -localtime -usb -usbdevice tablet
  39. 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
  40. Start NetworkManager GUI Applet
    • nm-applet &
  41. Set Password for MySQL Root
    • mysqladmin -u root password new-password
  42. Remove User account and Home dir
    • userdel -r {username}
  43. Mount an ISO image
    • mount -o loop -t iso9660 filename.iso /mnt/iso
  44. Create random passwords
    • head /dev/urandom | strings
  45. Show partions on a drive
    • sfdisk -l
  46. 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/
  47. How to rsync
    • rsync -r -a -v -e "ssh -l {username}" --delete {remote machine}:/dir /dir
  48. How to check memory
    •  ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid
  49. How to search and replace recursively within files
    •  find . -type f -exec sed -i s/search/replace/g {} +
  50. How to convert Flac to MP3
    • for file in *.flac; do flac -cd "$file" | lame -h - "${file%.flac}.mp3"; done
  51. How to check 3ware Hardware RAID status:
    •  tw_cli /c0 show
  52. Dirvish Vault first init
    •  dirvish -vault ''vaultname'' --init
  53. 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/
  54. 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
  55. How to enable ndadmin slot:
    • ndasadmin enable -s 1 -o w
  56. How to install Debian Kernel headers:
    • apt-get install linux-headers-$(uname -r)
  57. How to find the largest file/directory human readable from your current directory:
    • du -hsx * | sort -rh | head -10
  58. 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'
  59. GLOBAL REPLACE in the files (change call to mall in all *.kumac files):
    • awk '{gsub("call", "mall", $0); print > FILENAME}' *.kumac
  60. The fastest way to scan all your computers/network subnet for open ports ever:
    • nmap -T5 192.168.1.0/24
  61. Convert virtual image files:
    • ovftool --lax input.ovf output.vmx
  62. How to extract CPIO file:
    • cpio -id < filename
  63. How to remove all symbolic link:
    • find -type l -delete
  64. How to find device or partition block size:
    • blockdev --getbsz partition
  65. How to convert KVM to VMWARE:
    • qemu-img convert -O vmdk filename.qcow2 filename.vmdk
  66. List UUID of all disks:
    • ls /dev/disk/by-uuid -lt
  67. Add CDROM to apt:
    • apt-cdrom add
  68. Rebuild software RAID:
    • mdadm --assemble --scan
  69. Time stamp on history command:
    • HISTTIMEFORMAT="%d/%m/%y %T " && history<pre>
  70. Remount read/write:
    • mount -o remount, rw / 
  71. Find port number of running application:
    • lsof -Pan -p {PID} -i
  72. WAN IP Address from commandline:
    • curl -s ifconfig.co
  73. Burn CD/DVD commandline:
    • growisofs -dvd-compat -Z /dev/cdrom=filename.iso
  74. Bandwidth Test Commandline:
    • curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python -
  75. Fix E353: Nothing in register "
    • echo set clipboard=unnamed >> ~/.vimrc
  76. Find Out Which Process Is Listening Upon a Port:
    • netstat -tulpn
  77. Replace all spaces in files within a directory with an underscore:
    • for f in *\ *; do mv "$f" "${f// /_}"; done
  78. Disk usage of all directories including hidden:
    • du -sch .[!.]* *
  79. Check process by CPU and PID:
    • ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
  80. Create simple HTTP server from present working directory:
    • python -m SimpleHTTPServer
  81. Resize img file
    • qemu-img resize test.img 2G
  82. a wk vertical to horizontal
    • awk 'ORS=" "' filename
  83. Re-read partition table after modifications (SD or USB):
    • partprobe /dev/sdX
  84. Find with max depth of 3 directories:
    • find -maxdepth 3
  85. Find SCSI/SATA devices
    • lsscsi
  86. ecm uncompress multiple files:
    • for i in *; do  ecm-uncompress "$i"; done
  87. 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
  88. Find package dependencies from repo:
    • debfoster -d package
  89. List video drivers used. Search for "configuration":
    • dlshw -c video
  90. List all listening network ports:
    • netstat -ntpl
  91. Check TCP ports using netcat:
    • nc -w 5 -zv {ipaddress} {port}
  92. Check UPD ports using netcat:
    •  nc -u -w 5 -zv {ipaddress} {port}
  93. Show Debian/Ubuntu release information:
    • lsb_release  -a
  94. Reinstall GRUB on drives after OS is running:
    • dpkg-reconfigure grub-pc
  95. Cut example to get full names of users from passwd:
    • cut -d':' -f5 /etc/passwd
  96. Deletes any trailing whitespace at the end of each line:
    • :%s/\s\+$//e
  97. Check UDP port is open/closed:
    • map -sU -p port ip
  98. Unlink all symbolic links in dir:
    • find . -type l -exec unlink {} \;
  99. See process in memory:
    • ps wwu -C process
  100. See process tree of all processes on system:
    • ps axjf
  101. Sort processes memory from highest to lowest:
    • ps -o pid,user,%mem,command axf | sort -b -k3 -r
  102. Sort processes CPU from highest to lowest:
    • ps -o pid,user,%cpu,command axf | sort -b -k3 -r
  103. Display uncommented lines in a file:
    • cat {filename} | egrep -v "(^#.*|^$)"
  104. List all process running on port number
    • lsof -i :8080
  105. Show the time and date when Linux was first installed
    • ls -lact --full-time /etc |tail
  106. Show SSL Cert information
    • curl --insecure -v https://www.google.com 2>&1 | awk 'BEGIN { cert=0 } /^\* Server certificate:/ { cert=1 } /^\*/ { if (cert) print }'
  107. Find largest files by size
    • sudo find / -xdev  -type f -size +100M -exec ls -hla {} \; | sort -nk 5
  108. Display SSL Cert expiry date.
    • openssl x509 -enddate -noout -in file.pem
  109. Extract and reverse engineer .bin or .img files. Or any other binary:
    • binwalk --dd='.*' file.bin
  110. Extract compressed file system:
    • 7z x filename
  111. Unzip multiple files with spaces in name:
    • find . -name "*.zip" -exec sh -c 'unzip -n "{}" | head -n 7' \;
  112. Remove files past a certain day (Example 5 is five days):
    • find /path/to/files/* -mtime +5 -exec rm {} \;
  113. You can use the command below to probe the port 22:
    • sudo lsof -i :22
  114. Print history without line numbers or date:
    • fc -l -n 1 | sed 's/^\s*//'
  115. Set the "immutable" attribute to make a file non-writable:
    • chattr +i {filename}
  116. Set the "unimmutable" attribute to make a file writable:
    • chattr -i {filename}
  117. Check webserver a host is using:
    •  wget -q -O- --save-headers domainname.com | grep '^[Ss]erver:' | awk '{print $2}'
  118. Look at errors in specific services in systemd:
    • journalctl -xe -u {service name}
  119. Convert vertical text to horizontal:
    • tr '\n' ' ' <file.txt
  120. Find and sort files by disk space
    • du -sch $(ls -A) 2> /dev/null | sort -rh
  121. Find files that uses port 443
    • lsof -i :443
  122. Find which directory has the most files:
    • find . -type d | cut -d/ -f 2 | uniq -c