Linux Commands
A variegated collection of useful Linux commands, in no particular order
testparm smb.conf= Check the syntax of the Samba configuration filecat /proc/interrupts= Show the IRQscat /proc/dma= Show the DMA channelsalignmargins= Align margins of a printer (it actually prints a test page with the margins)import img= Take a screenshot of the desktop inimgxwd -out img= Take a screenshot of a window (to be selected with the mouse) and saves it inimgin a format readable byxwudtput reset= Reset (clean) the terminaldisplay 'vid:*.jpg'= Make a thumbnails gallery of all the images in the current directorymontage $images outputimg= Make a single image of all$imageszip -J file.zip /directory/files= Make a zip file of files stripping the directories tree (basically, put every file at the same level in the zip file)lsof -V -P= Show all opened ports and the relative processeslsof (file|device)= Show the processes using file|devicelsof -i TCP:4000= Check if a specific port is in usecdrecord dev=scsihost blank=fast= Blank a CDRW in fast mode. Use “all” for the complete modess -s= Print statistics about the network packetstcpdump -q= Show packets that are being transferred over the networkxwininfo= Show many informations about the selected windowuuencode file name | mail user= Encrypt the binary file as “name” and send it via e-mail to “user”uudecode file= Decrypt a filenmap -P -O url= Inquiry about open ports and the OS running on urlperl -MCPAN -e 'install module'= Install a Perl moduleperl -Mmodulename -e 1= Check if “modulename” is already installed
useradd -d home -g group -G group1,group2 name= Add an user with “name”, with home directory as “home”, that belongs to group “group” and also to “group1” and “group2”mkisofs -v -r -l --allow-leading-dots -R -J -T -o img.iso files= Make an iso file (RockRidge + Joliet)split -B size file outputfile= Split file in as many pieces of outputfile as given size (in bytes)rar a -v1000000k archive.rar file= Make a rar archive of at most 1000000 kilobytes from file(s)xrdb -load .Xdefaults= Load configuration in.Xdefaultsperl -e shell -mcpan= Open a shell to manage Perl modulesi /module/= Search a moduleinstall module= Download and install a module
formail -s procmail < mbox= Scan a mbox with the current Procmail rulessetkeycodes code n= Map an unrecognized key to n so it can be bind to an atcion withxbindkeys(see logs to discover the code)xev= Show info about the pressed keybogoutil -p wordlist.db word= Show if word is classified as ham or spam by bogoutilsox file.wav -v n output.wav= Raise or lower volum of a wav according to the value of n (the higher it is, the higher it’ll be the volume too)screen -xRR= Launch screen at login. To be inserted in the shell configuration file (bashrc, zshrc etc.)growisofs -Z /dev/hdd=image.iso= Burn the iso file in the specified devicecupsdoprint -H localhost:631 -P printername -J jobname -U login_name file.ps= Print the file.ps with the selected printerdvdauthor -T directory= Create the TOC (the file VIDEO_TS.IFO) of a dvd in directorydvdauthor -t dvdvideos -v videooptions -a audiooptions directory= Make the vob files from videos using the parameters for video and audio givengtf hhhh wwww refresh_rate= Print the Modeline forxorg.confof the given resolution (height and width) and refresh rate (in Hz)cat /proc/fb0/modes= Show supported resolution by the current framebuffer device (fb0)pacman -Qqe | grep -vx "$(pacman -Qqm)"= Print the list of installed packages in Archlinux (does not include those in AUR)zcat initrd_image.img | cpio –list= Show contents of a cpio boot imagepdfimages -j file.pdf directory= Extract in ppm (Gimp can open it) all the images in file.pdf to directory. Pdfimages is in poppler packagecurl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} url= Returns, respectively, the time needed to connect to url, the time the server took to reply and the total time taken to satisfy the requestwget -E -H -k -K -p -x webpage= Download webpage, followin images and css links and converting them to local to make browsing offline easierwget -e robots=off --wait 1 -x -m -k url= Download url, convert link to local, wait 1 second between requests to not overload the server and ignore the robots fileudevinfo -a -pudevinfo -q path -n device= Get info on a device useful to then write an udev rule about itffmpeg -i video audio= Extract audio from a video. To know in what format it is, useffmpeg -i videoand look for the line that says “Stream…..Audio”ffmpeg -i youtube.flv -ar 48000 -ac 2 -b 800000 youtube.avi= Convert in an avi a flv file, fixing audio out of sync issues.-bis the bitrate, increase it to make the final result look better (and bigger)w= Show info about the users logged and what processes they have launchedstat file|directory= Show complete info about a file or a directory (inode number, size, occupied clusters, modification/access time etc.)trap 'echo message' EXIT= Execute the command, in this case echoing “message”, when the script/shell receives the signal to exit (EXIT)cat /proc/cmdline= Show kernel parameters sent at bootnmap -sV host= Scan all open ports on host, trying to identify also the services using themnetstat -antulp host= Scan open ports and active connections on host, returning also information on the processescdrdao copy --on-the-fly --speed 4 --read-raw --fast-toc --device 0,1,0 --driver generic-mmc-raw --source-device 0,0,0 --source-driver generic-mmc-raw= On the fly copy of a cd (check the device numbers, of course)cdrdao read-cd --device 6,0,0 --driver generic-mmc-raw -v 2 --datafile CD.bin --read-raw CD.toc= On the fly copy of a cd containing multisession trackskill -9 $(ps -o pid= -u user)= Kill all processes started by a given user, basically stopping his use of the computerfind / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print= Find all directories that haven’t the sticky bit set and are writable by everybody (a known security hole)find / -xdev -type f \( -perm -4000 -o -perm -2000 \) -print= Find all files with suid/sgid setfind / -xdev -type f -perm -0002 -print= Find all files that are editable by everybodyfind / -xdev \( -nouser -o -nogroup \) -print= Find all files that haven’t a group or a user or have and invalid onecat /proc/net/nf_conntrack= List all recent connections, with ports, addresses and protocols. Needs Ip Conntrack support in the kernelmodinfo module= Show detailed info about a kernel modulels -d */= Show only subdirectories of the current directorylsof +p pid= Show opened files by the process with that pidffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg= Record a screencast of the desktop at 25fps with a 800x600 resolutiongrep ^[^#] config_file= Strip and print a file of comments (#) and empty linesgrep -v '#' config_file= As above but keep empty linesidentify -format %[exif:*] img= Show Exif data of imgcurl -v url= Connect to url and show request and response http headerspacman -Qm= Show installed packages that aren’t present in the pacman database. Usually they are local and aur packagesdiff -rupN original_dir/ new_dir/ > file.patch= Make a patch containing the differences in all files betweenoriginal_dirandnew_dirnetstat -c host= Show info about connection of host in a continuosly updated way (needs to be killed then)curl --head -s url -D -= Connect to url with a HEAD request, outputting only the response headerscuebreakpoints file.cue | shnsplit -o flac -t "%p-%a-%n-%t" file.flac= Split a flac file containg a full album into tracks according to the cue file. See also Archwiki entry.cuetag.sh file.cue split-track*.flac= Add tags to the various tracks from the cue file. Usually it is to be aftercuebreakpoints. See also Archwiki entrysp-sc link 3908 8908 > /dev/null &= Connect to the Sopcast link at port 3908 and open to listen on localhost on port 8908mplayer http://localhost:8908/tv.asf= Play the Sopcast video from abovepgrep cmd= Return the pid of cm. Likeps | grep cmdbut doesn’t print also the grep pidcsplit file model= Split file in various copies named like xx00, xx01 etc. Model can be a line number or a regular expressionenv -i cmd= Ignore any environment variable for the execution of cmdls | grep -x ".\{6\}"= Return only file or directory names whose name is long exactly 6 charactersfind path -size +1000k= Find only files bigger than 1Mb in path. Using instead-1000klooks for files smaller than 1Mb and without both-and+looks for files of exactly 1Mbfc= Open with$EDITORthe last executed command and thus enable modifying it, reexecuting it at the endls -t= List files ordered by modification date, the most recent firstls -X= List files ordered by extensionls -S= List files ordered by size, the bigger ones firstfind | xargs file= List files in current directory as it was used the commandfileon them allcat > file= Write text to a file without any need of a real editor. Start typing after this command and terminate input with Ctrl+dbind -P= Show all available Bash functions and their keybindingsobjdump -D prog= Disassembleproggrep -H regexp files= Print filename of every files matching the regexpopenssl x509 -noout -fingerprint -in cert.pem= Print the SHA1 checksum of the certificate cert.pemopenssl s_client -connect server -showcerts= Show SSL info and certificates of serveropenssl s_client -host server -port portnumber -verify 1 -debug= debug a secure connection withserveronportnumbernm -D cmd= Show all names, variables and functions, used by cmdcat /proc/pid/smaps= Show loaded memory segments by the process with suchpidgenisoimage -r -J -o file.iso directory= Make an iso, readable both on Windows and Linux, of the files in directorywodim -v dev=/dev/sr0 file.iso= Burn on the empty medium in /dev/sr0 the isotop -pnnn -pnnn= Start top telling it to monitor only processes whose pid isnnnloginctl list-seats= Lists seatsloginctl seat-status seat0= Shows list of hardware assigned toseat0grep -Ri --include="*.py" abc directory/= Search for “abc” in directory but only considering.pyfileslspci -k= Print a list of active hardware devices with the corresponding kernel module they need to workmodprobe -c= Display a complete module configuration, including defaults and directives in /etc/modules.conf (or /etc/modules-load.d/, depending on the Linux distribution)ip route show= Display routing tableip route show table 255= Display local addresses route tableip route add prohibit 1.1.1.1= Prohibit all access to the specified IP addressip addr show= Display IP and MAC addresses of every network interfacearp= Display the ARP cachemsgcat --color=test= Output various tests to check the appearance of colours on your terminalgcc -E file.c= See all the declarations from file.c and from all the headers included by itdate -d "string"= Emits current date and time modified by string. For example,2 dayswill add 2 days to current date,1 hour agowill subtract 1 hour,last yearwill emit the date exactly 1 year ago etc.date -r file= Returns when the file was last modifiedwho -b= Print time and date of the last system bootwatch -n 10 kill -USR1 4834= Print every second (0.1sec * 10) the status of the process having pid 4834diff -rq dir1/ dir2/= Print a summary of the differences betweendir1anddir2cat -s file= Output only non-repeated lines from file. Likeuniqcat -a file= Output file showing tabs, non printing characters and a$for each newline character. It’s the same as usingcat -vETstapler sel input.pdf 23-25 33 40-60 output.pdf= Create a new pdf (output.pdf) frominput.pdfonly including a specific range of pages (in the example, 23 through 25, the page 33 and from page 40 through 60)bsdtar xf zipfile= Extract from a zip archive. It may work also with incomplete/corrupt ones or in general whereunzipwon’t.find . -name "pattern" -ls | awk '{total += $7} END {print total}'= Print the total size of files matchingpatterncurl -X POST -d "fname=Mark&lname=Babe" url= Send a POST request tourlwith given parameters. It’s also possible to send a JSON file containing the parameters using-d @parameters.jsonsyntaxdu -s directory/= Show only the total sum of occupied space on disk ofdirectory, and not every single file alsofind Maildir/ -type f | grep -vE ',[^,]*S[^,]*$'= Find all unread emails in the maildir (Maildir format)nl $file= Print the file with the lines’ numbers next to each line. By default it skips empty lines, to include them add-b a.ip -s link show= Print all the network interfaces present on the system with additional statistics about themip neighbour show= Show the ARP tableroute add -host $ip reject= Reject all traffic to host with IP address of$ipls -Z= Display SELinux context for the fileslast= Display a chronological list of users’ accesseslastb= Display a chronological list of failed users’ accesses (“bad logins”)lastlog= Display the last accesses of each daemons and usersdig $domain +noall +answer= Display the IP address of$domainwith a TTL of how long the data is kept in local DNS cachefile -i $filename= Show the mimetype and locale of$filenameddjvu --format=pdf file.djvu file.pdf= Convert a djvu file to a pdfgs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dCompressFonts=true -dDetectDuplicateImages -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOUtputFile=file.pdf file_to_optimize.pdf= Compress and optimize a pdf./ebookmeans a medium quality, 150dpi. Alternatives are/prepress, which produces a 300dpi pdf, and/screen, for a 72dpi, good for screen reading only, pdf. The resolution can also be forced with the option-r72(for 72dpi).pactl list | grep codec= Check what bluetooth codec is being used (need bluez and pavucontrol installed)yt-dlp -S "res:720" video= Downloadvideobut only up to 720p resolution, or lower if not availableasciidoc -b docbook file.adoc= Convert an asciidoc file to a docbook XML. This is useful to then convert it later to markdown or elsepandoc -f docbook file.xml -o file.md= Take the docbook XML file generated above and convert it to markdown