Thursday, 13 April 2017

List of generic commands for Linux




System Monitoring and debugging
Command Description
# Free -m displays status of RAM in megabytes
# Kill -9 process_id force closure of the process and finish
# Kill -1 process_id force the process to reload configuration
# Last reboot show history reboot
# lsmod mooduli displays the loaded kernel
# Lsof -p process_id displays a list of files opened by processes
# Lsof / home / user1 displays a list of open files in a given path system
# Ps -eafw displays system processes
# Ps -e -o pid, args --forest displays processes in a hierarchical system
# pstree shows a tree of system processes
# Smartctl -A / dev / hda monitoring reliability of a hard-disk through SMART
# Smartctl -i / dev / hda check if SMART is active on a hard-disk
# Strace -c ls> / dev / null displays the system calls made and received by a process
# Strace -f -e open ls> / dev / null display library calls
# Tail / var / log / dmesg show events inherent to the process of booting kernel
# Tail / var / log / messages show system events
# top display linux tasks using most cpu
# Watch -n1 'cat / proc / interrupts' shows the interrupts in real time






System Information
CommandDescription
# archshows the machine architecture
# Cal 2007show the timetable of 2007
# Cat / proc / cpuinfoshow information CPU
# Cat / proc / interruptsshow interrupts
# Cat / proc / meminfocheck the memory in use
# Cat / proc / swapsshow file (s) swap
# Cat / proc / versionsee the kernel version
# Cat / proc / net / devview network adapters
# Cat / proc / mountsshow file (s) mounted
# Clock -wdefinitavamente save the date changes on BIOS
# at your placeview the system date
# 041217002007.00 datesset date and time - MonthDayhoursMinutesYear.Seconds
# Dmidecode -qshow hardware system components - (SMBIOS / DMI)
# Hdparm -i / dev / hdadisplays the information and the characteristics of a hard-disk
-tT # hdparm / dev / sdaperforming a test reading on a hard-disk
# Lspci -tvdisplay PCI devices
# Lsusb -tvshow USB devices
# Uname -mshows the architecture of machine (2)
# Uname -rshows the kernel version in use
Files and Directories
CommandDescription
# Cd / homeenter to directory '/ home'
# Cd ..go back one level
# Cd ../ ..go back two levels
# cdGo to the home directory
# Cd ~ user1Go to the home directory
# Cd -go to previous directory
# Cp file1 file2copy a file
# Cp dir / *.copy all files of a directory within the current working directory
# Cp -a dir1 dir2copy a directory
# Iconv -lshows all sets of known characters
# Iconv -f -t fromEncoding toEncoding inputFile> outputFileconvert the encoding of characters from one format to another
# Find. -maxdepth 1 -name * .jpg -print -exec convertchange the size of all the files ".jpg? 559" in the local directory (requires ImageMagick)
# Ln -s file1 LNK1create a symbolic link to the file (or directory) 'file1' called LNK1
# Ln file1 LNK1create a physical link to the file (or directory) 'file1' called LNK1
# lsview files of directory
# Ls -Fdistinguish between files and directories
# Ls -lshow details of files and directories
# Ls -ashow hidden files
# Ls * [0-9] *show files and directory containing numbers
# lstreeshow files and directories in a tree starting from root (2)
# Mkdir dir1create directory 'dir1'
# Mkdir dir1 dir2create two directories simultaneously
# Mkdir -p / tmp / dir1 / dir2create a directory tree
# Mv dir1 new_dirrename / move a file or directory
# pwdshow the path of the working directory
# Rm -f file1eliminate 'file1' files
# Rm -rf dir1recursively delete the directory 'dir1' and contents
# Rm -rf dir1 dir2remove two directories recursively and their contents with a single command
# Rmdir dir1delete the directory 'dir1'
# Touch -t 0712250000 file1modify a file or directory timestamp - (YYMMDDHHMM)
# treeshow files and directories in a tree starting from /


file Search
CommandDescription
# Find / -name file1search file and directory into root filesystem from '/'
# Find / -user user1search files and directories belonging to 'user1'
# Find / home / user1 -name \ *. Binsearch the directory '/ home / user1' all files with the extension '.bin'
# Find / usr / bin -type f -atime +100search files (binaries) not used in the last 100 days
# Find / usr / bin -type f -mtime -10search for all files created or changed within 10 days
# Find / -name * .rpm -exec chmod 755 '{}' \;search files with '.rpm' extension and modify permits
# Find / -xdev -name \ *. Rpmsearch files with '.rpm' extension ignoring removable partitions as cdrom, pen-drive, etc. ...
# Locate \ *. Pssearch files with the '.ps' extension - first run 'updatedb'
# Whereis haltshow location of a binary file, source
# Which haltshow full path to a binary / executable
Mounting a Filesystem
CommandDescription
# Fuser -km / mnt / hda2force umount when the device is busy
# Mount / dev / hda2 / mnt / hda2mount disk called hda2 - verify existence of the directory '/ mnt / hda2'
# Mount / dev / cdrom / mnt / cdrommount a cdrom / dvdrom
# Mount -o loop file.iso / mnt / cdromISO9660 mount a file or iso image
# Mount -t vfat / dev / hda5 / mnt / hda5mount a Windows FAT32] filesystem
# Mount / dev / sda1 / mnt / usbdiskmount a usb pendrive or flash
# Mount -t smbfs -o username = user, password = pass // WinClient / share / mnt / sharemount a windows network share
# Umount / dev / hda2disassemble the hda2 hard - get out of the mount point '/ mnt / hda2' before dismantling
# Umount -n / mnt / hda2umount without writing the file / etc / mtab - useful when the file is read-only or the hard disk is full
disk Space
CommandDescription
# Df -hview the list of partitions mounted
# Dpkg-query -W -f = '$ {Installed-Size; 10 t} $ {Package} n' | sort -k1,1nshows the disk space used by installed deb packages, sorting by size (debian, ubuntu and alike)
# Du -sh dir1knowing the disk space used by directory 'dir1'
# Du -sk * | sort rnshow size of the files and directories sorted by size
# Ls -lSr | moreshow size of the files and directories ordered by size
Users and Groups
CommandDescription
# Chage -E 2005-12-31 user1set the password expiration for a user
# Groupadd [group]create a new group
# Groupdel [group]delete a group
# Groupmod -n moon sunrename a group]
# grpckCheck the correct syntax and format of '/ etc / group file' and the actual existence of the groups
# Newgrp - [group]Please log in temporarily to a new group to change the default group of newly created files
# passwdchange your password
# Passwd user1change a user password (only by root)
# pwckCheck the correct syntax and format of '/ etc / passwd' file and users existence
# Useradd -c "User Linux" -g admin -d / home / user1 -s / bin / bash user1create a new user that belongs to the group "admin"
# Useradd user1create a new user
# Userdel -r user1delete a user ( '-r' eliminates home directory)
# Usermod -c "User FTP" -g system -d / ftp / user1 -s / bin / nologin user1edit user attributes
Permits on Files
Command
Description
# Chgrp group1 file1modify the group membership of a file
# Chmod ugo + rwx directory1set permissions reading (r), write (w) and (x) access to users owner (u) group (g) and others (o)
# Chmod go-rwx directory1remove permits reading (r), write (w) and (x) access to users group (g) and others (o)
# Chmod u + s / bin / file1set SUID bit on a binary file - the user that running that file gets same privileges as owner
# Chmod us / bin / file1disable SUID bit on a binary file
# Chmod g + s / home / publicset SGID bit on a directory - similar to SUID but for directory
# Chmod gs / home / publicdisable SGID bit on a directory
# Chmod o + t / home / publicset STIKY bit on a directory - allows files deletion only to legitimate owners
# Chmod ot / home / publicoff STIKY bit on a directory
# Chown user1 file1change the ownership of a file
# Chown -R user1 directory1change user owner of a directory and all files and directories contained inside
# Chown user1: group1 file1change user and group ownership of a file
# Find / -perm -u + sview all files on the system with SUID configured
# Ls -lhshow permits
# Ls / tmp | pr -T5 -W $ COLUMNSdivide the terminal into 5 columns
Special Attributes on files
CommandDescription
# Chattr + a file1allows a file write opening only append mode
# Chattr + c file1allows that a file is compressed / decompressed automatically by the kernel
# Chattr + d file1It makes sure that ignores Dump the files during a backup program
# Chattr + i file1It makes it an immutable file, which can not be removed, altered, renamed or linked
# Chattr + s file1It allows a file to be deleted in a secure manner, by resetting the blocks on the disk
# Chattr + S file1It makes sure that if a file is modified changes are written in synchronous mode as with sync
# Chattr + u file1It allows you to recover the contents of a file even if it is canceled
# lsattrshow specials attributes
Archives and compressed files
CommandDescription
# Bunzip2 file1.bz2unzip the file named 'file1.bz2'
# Bzip2 file1compress a file called 'file1'
# Gunzip file1.gzunzip the file named 'file1.gz'
# Gzip file1compress a file called 'file1'
# Gzip -9 file1compress with maximum compression
# Rar in file1.rar test_filecreate an archive rar called 'file1.rar'
# Rar in file1.rar file1 file2 dir1compress rar simultaneously 'file1', 'file2' and 'dir1'
# Rar x file1.rardecompress a rar archive
# Tar -cvf archive.tar file1create a uncompressed tarball
# Tar -cvf archive.tar file1 file2 dir1create an archive containing 'file1', 'file2' and 'dir1'
# Tar tf archive.tarview the contents of an archive
# Tar -xvf archive.tarextract a tar archive
# Tar -xvf archive.tar -C / tmpextract a tarball into / tmp
# Tar -cvfj archive.tar.bz2 dir1create a tarball compressed into bzip2
# Tar -xvfj archive.tar.bz2decompress a tarball compressed into bzip2
# Tar -cvfz archive.tar.gz dir1create a tarball compressed into gzip
# Tar -xvfz archive.tar.gzdecompress a tarball compressed into gzip
# Unrar x file1.rardecompress a rar archive
# Unzip file1.zipuncompress a zip archive
# Zip file1.zip file1create an archive compressed in zip
# File1.zip zip -r file1 file2 dir1zipping multiple files and directories simultaneously
View the contents of a file
CommandDescription
# Cat file1view the contents of a file starting from the first row
# Head -2 file1view first two lines of a file
# Less file1similar to the command 'more' but which allows you to scroll through the file in both forward and backward
# More file1view the contents of a long file
# Tac file1view the contents of a file starting from the last line
# Tail -2 file1view last two lines of a file
# Tail -f / var / log / messagesview in real time what is added to a file
Text Manipulation
CommandDescription
# Cat example.txt | awk 'NR% 2 == 1'remove all even lines from example.txt
# Echo abc | awk '{print $ 1}'the first column of a line
# Echo abc | awk '{print $ 1, $ 3}'print the first and third column of a line
# Cat -n file1number row of a file
# Comm -1 file1 file2compare contents of two files by deleting only unique lines from 'file1'
# Comm -2 file1 file2compare contents of two files by deleting only unique lines from 'file2'
# Comm -3 file1 file2compare contents of two files by deleting only the lines that appear on both files
# Diff file1 file2Find the differences between two files
# Grep Aug / var / log / messagessearch for "Aug" on file 'messages'
# Grep ^ Aug / var / log / messageslook up words that begin with "Aug" on file 'messages'
# Grep [0-9] / var / log / messagesselect in the 'messages file all lines that contain numbers
# Grep Aug -R / var / log / *extend the search string "Aug" at directory '/ var / log' and below
# Paste file1 file2merging contents of two files for columns
# Paste -d '+' file1 file2merging contents of two files for columns with delimiter '+' in quotes
# Sdiff file1 file2find differences between two files and merge interactively alike "diff"
# Sed 's / string1 / string2 / g' example.txtreplace "string1" with "string2" example.txt
# Sed '/ ^ $ / d' example.txtremove all blank lines from example.txt
# Sed '/ * # / d; / ^ $ / D 'example.txtremove comments and blank lines from example.txt
# Sed -e '1d' exampe.txteliminates the first line from file example.txt
# Sed -n '/ string1 / p'view only lines that contain the word "string1"
# Sed -e 's / * $ //' example.txtremove empty characters at the end of each line
# Sed -e 's / string1 // g' example.txtremove only the word "string1" from text and leave intact all
# Sed -n '1,5p' example.txtprint from 1th to 5th row of example.txt
# Sed -n '5p; 5q' example.txtprint row 5 of a movie
# Sed -e 's / 00/0 / g' example.txtreplace more zeros with a single zero
# Sort file1 file2sort contents of two files
# Sort file1 file2 | uniqsort contents of two files omitting lines repeated
# Sort file1 file2 | uniq -usort contents of two files by viewing only unique line
# Sort file1 file2 | uniq -dsort contents of two files by viewing only duplicate line
# Echo 'word' | tr '[: lower:]' '[: upper:]'convert from lower case to upper case
Filesystem Analysis
CommandDescription
# Badblocks -v / dev / hda1check bad blocks on disk hda1
# Dosfsck / dev / hda1repair / check integrity of dos filesystem on disk hda1
# E2fsck / dev / hda1repair / check integrity of ext2 filesystem on disk hda1
# E2fsck -j / dev / hda1repair / check integrity of ext3 filesystem on disk hda1
# Fsck / dev / hda1repair / check integrity of linux filesystem on disk hda1
# Fsck.ext2 / dev / hda1repair / check integrity of ext2 filesystem on disk hda1
# Fsck.ext3 / dev / hda1repair / check integrity of ext3 filesystem on disk hda1
# Fsck.vfat / dev / hda1repair / check integrity of fat filesystem on disk hda1
# Fsck.msdos / dev / hda1repair / check integrity of dos filesystem on disk hda1
Format a Filesystem
CommandDescription
# Fdformat -n / dev / fd0format a floppy disk
# Mke2fs / dev / hda1create the filesystem type linux ext2 on hda1 partition
# Mke2fs -j / dev / hda1create the filesystem type linux ext3 (journal) on hda1 partition
# Mkfs / dev / hda1create a filesystem type linux on hda1 partition
# Mkfs -t vfat 32 -F / dev / hda1create a FAT32 filesystem
# Mkswap / dev / hda3create a swap filesystem
Filesystem SWAP
CommandDescription
# Mkswap / dev / hda3create a swap filesystem
# Swapon / dev / hda3activating a new swap partition
# Swapon / dev / hda2 / dev / hdb3activate two swap partitions
Backup Techniques
CommandDescription
# Find / var / log -name '* .log' | tar cv --files-from = - | bzip2> log.tar.bz2find all files with '.log' extention and make an bzip archive
# Find / home / user1 -name '* .txt' | xargs cp -av --target-directory = / home / backup / --parentsfind and copy all files with '.txt' from one directory
# Dd bs = 1M if = / dev / hda | gzip | ssh user @ ip_addr 'dd of = hda.gz'a backup of a local hard disk on remote host via ssh
# Dd if = / dev / sda of = / tmp / file1backup content of the harddrive to a local file
# Dd if = / dev / hda of = / dev / fd0 bs = 512 count = 1make a copy of MBR (Master Boot Record) to floppy
# Dd if = / dev / fd0 of = / dev / hda bs = 512 count = 1restore MBR from backup copy saved to floppy
# Dump -0aj /tmp/home0.bak -f / homefull backup of directory '/ home'
# Dump -1aj /tmp/home0.bak -f / homeincremental backup of directory '/ home'
# Restore -if /tmp/home0.bakrestoring a backup interactively
# Rsync --delete -rogpav / home / tmpdirectory synchronization between
# -rogpav rsync -e ssh --delete / home ip_address: / tmprsync via ssh tunnel
# -az rsync -e ssh --delete ip_addr: / home / public / home / localsynchronize a local directory with a remote directory via ssh and compression
# -az rsync -e ssh --delete / home / local ip_addr: / home / publicsynchronize a remote directory with a local directory via ssh and compression
# Tar -Puf backup.tar / home / userincremental backup of directory '/ home / user'
# (Cd / tmp / local / && tar c.) | ssh user @ -C ip_addr 'cd / home / share / && tar x -p'copy the contents of a directory on remote directory via ssh
# (Tar c / home) | ssh user @ -C ip_addr 'cd / home / backup-home && tar x -p'copy a local directory on remote directory via ssh
# Tar cf -. | (Cd / tmp / backup, tar xf -)local copy preserving permits and links from a directory to another
CDROM
CommandDescription
# Cd-paranoia -Brepairing audio tracks from a CD to wav files
# Cdrecord -v gracetime = 2 dev = / dev / cdrom blank = fast -eject -forceerase a rewritable cdrom
# Cdrecord -v dev = / dev / cdrom cd.isoburn an ISO image
# Gzip -dc cd_iso.gz | cdrecord dev = / dev / cdrom -burn a compressed ISO image
# Cdrecord --scanbusscan bus to identify the channel scsi
# Dd if = / dev / hdc | md5sumperform an md5sum on a device, similar to a CD
# Mkisofs / dev / cdrom> cd.isocreate an iso image of cdrom on disk
# Mkisofs / dev / cdrom | gzip> cd_iso.gzcreate a compressed iso image of cdrom on disk
# Mkisofs -J -ALLOW-leading-dots -R -Vcreate an iso image of a directory to burn
# Mount -o loop cd.iso / mnt / isomount an ISO image
Network (LAN / WiFi)
CommandDescription
# Dhclient eth0active interface 'eth0' in DHCP mode
# Ethtool eth0show network statistics 'eth0'
# Host www.example.comhostname resolution to ip address and viceversa
# hostnameshows system hostname
# Ifconfig eth0show configuration of an ethernet network card
# Ifconfig eth0 192.168.1.1 netmask 255.255.255.0configure ip address
# Ifconfig eth0 promiscconfigures 'eth0' in promiscuous mode to collect packets (sniffing)
# Ifdown eth0disable an interface 'eth0'
# Ifup eth0active interface 'eth0'
# Ip link showshow link status of all network interfaces
# Iwconfig eth1show configuration of a wireless network card
# Iwlist scanscans for available wireless networks
# Mii-tool eth0show link status of 'eth0'
# Netstat -tupshow all active network connections and their PID
# Netstat -tuplshow all network services listening on the system and their PID
# Netstat rnshow routing table alike "route -n"
# Nslookup www.example.comhostname resolution to ip address and viceversa
# Route -nshow routing table
# Route add -net 0/0 gw IP_GATEWAYconfigured default gateway
# Route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1configures static route to reach the network '192.168.0.0/16'
# Route of 0/0 gw IP_GATEWAYremove static route
# Echo "1"> / proc / sys / net / ipv4 / ip_forwardactivate ip routing
# Tcpdump tcp port 80displays all HTTP traffic
# Whois www.ex.comlookup on Whois database to obtain information about the domain / hosts
Microsoft Windows networks (samba)
Command
Description
# Mount -t smbfs -o username = user, password = pass // WinClient / share / mnt / sharemount a windows network share
# Nbtscan ip_addrnetbios name resolution
# Nmblookup -A ip_addrnetbios name resolution
# Smbclient -L ip_addr / hostnameshow remote shares of a windows host
# Smbget -RR smb: // ip_addr / sharelike wget can download files from a host windows via smb
IPTABLES (firewall)
CommandDescription
# Iptables -t filter -Lshow all chains of filtering table
# Iptables -t nat -Lshow all chains of nat table
# Iptables -t filter -Fclear all rules from filtering table
# Iptables -F -t natclear all rules from table nat
# Iptables -t filter -Xerases any user-created chains
# Iptables -t filter -A INPUT -p tcp telnet --dport j ACCEPTallow telnet connections to input
# Iptables -t filter -A OUTPUT -p tcp --dport http -j DROPblock HTTP connections to output
# Iptables -t filter -A FORWARD -p tcp pop3 --dport j ACCEPTallow POP3 connections to forward chain
# Iptables -t filter -A INPUT -j LOG --log-prefixlogging on the chain input
# Iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADEconfigure a PAT (Port Address Traslation) on eth0 masking outbound packets
# Iptables -t nat -A PREROUTING -d 192.168.0.11 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10.0.0.2:12the redirect packets addressed to a host to another host
useful commands
Command Description
# Alias ​​hh = 'history' set an alias for a command - hh = history
# Apropos ... keyword displays a list of commands that pertain to keywords of a program, useful when you know what your program does, but do not remember the name of the program
# chsh change shell
# Chsh --list-shells This command shows any remote users logged on the system
# Gpg -c file1 cryptare a file with GNU Privacy Guard
# Gpg file1.gpg decrypt a file with GNU Privacy Guard
# Ldd / usr / bin / ssh show shared libraries required by ssh program
# Man ping displays a manual to get information about, for example, the ping command
# Mkbootdisk --device / dev / fd0 'uname -r` create a boot disk
# Wget -r www.example.com download an entire website
# Wget -c www.example.com/file.iso download a file with the ability to stop the download and resume later
# Echo 'wget -c www.ex.com/files.iso' | at 19:00 start a download at any given time
# Whatis ... keyword displays information on what a program does
# Who -a shows users logged in a detailed manner
Shutdown, Restart and Logout of a system
Command Description
# Shutdown -h now system shutdown
# Shutdown -h 16:30 & planned shutdown of the system
# Shutdown -c cancel a planned shutdown of the system
# Shutdown -r now reboot the system

No comments:

Post a Comment