DEV Community

Cover image for 50 interesting Linux command lines
Girish Venkatachalam
Girish Venkatachalam

Posted on

50 interesting Linux command lines

  1. Convert CRLF terminated files to just CR
$ dos2unix file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Check if JSON is valid
$ json_verify < file.json
Enter fullscreen mode Exit fullscreen mode
  1. Same as above but prints out nicely.
$ jq < file.json
Enter fullscreen mode Exit fullscreen mode
  1. Get rid of duplicate spaces occuring together
 $ tr -s ' ' < file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Send mail from command line
$ mutt -s hi foo@yahoo.com < /tmp/mail.txt
Enter fullscreen mode Exit fullscreen mode
  1. Move in bulk based on patterns
$ mmv -v '*' '#1.jpg'
Enter fullscreen mode Exit fullscreen mode
  1. Use interactive file deletion DOS style (midnight commander DOS style UI)
$ mc
Enter fullscreen mode Exit fullscreen mode
  1. Fancy list files (show dirs with /)
$ ls -F
Enter fullscreen mode Exit fullscreen mode
  1. Show a file with line numbers
 $ cat -n file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Use cut to split fields
 $ echo 1:2:3 | cut -d: -f2
Enter fullscreen mode Exit fullscreen mode
  1. Edit file in place and do search and replace
 $ perl -pi -e 's/old/new/' file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Same as above but not in place
 $ sed -e 's/old/new/' file.txt > new.txt
Enter fullscreen mode Exit fullscreen mode
  1. Spidermonkey (interactive js shell)
$ js 
Enter fullscreen mode Exit fullscreen mode
$ node
Enter fullscreen mode Exit fullscreen mode
  1. Simple video to audio conversion
 $ ffmpeg -i file.mp4 song.mp3
Enter fullscreen mode Exit fullscreen mode
  1. Download youtube video to disk
 $ youtube-dl https://youtu.be/XXXX
Enter fullscreen mode Exit fullscreen mode
  1. Same as above, faster
 $ yt-dlp https://youtu.be/XXX
Enter fullscreen mode Exit fullscreen mode
  1. Show progress bar or ETA with pipeviewer
 $ cat file.tgz | pv | tar zxpf
Enter fullscreen mode Exit fullscreen mode
  1. Play gif animation
 $ mplayer file.gif
Enter fullscreen mode Exit fullscreen mode
  1. View image
 $ qiv file.jpg
Enter fullscreen mode Exit fullscreen mode
  1. Same as above
 $ qview file.webp
Enter fullscreen mode Exit fullscreen mode
  1. Same as above
 $ xloadimage file.png
Enter fullscreen mode Exit fullscreen mode
  1. Same as above
 $ display file.png
Enter fullscreen mode Exit fullscreen mode
  1. Nice PDF viewer
 $ mupdf file.pdf
Enter fullscreen mode Exit fullscreen mode
  1. Fire up a web server using current dir
 $ http-server
Enter fullscreen mode Exit fullscreen mode
  1. Fire up web server to interpret markdown files
 $ grip
Enter fullscreen mode Exit fullscreen mode
  1. Do a simple file upload to FTP or HTTP
 $ curl -T file.input ftp://remote/dir/A
Enter fullscreen mode Exit fullscreen mode
  1. Do a fast download breaking file into chunks and fetch using multiple TCP connections
 $ axel <URL>
Enter fullscreen mode Exit fullscreen mode
  1. Figure out common lines
 $ comm file.txt file2.txt
Enter fullscreen mode Exit fullscreen mode
  1. Compare binary files
 $ diff a.bin b.bin
Enter fullscreen mode Exit fullscreen mode
  1. Printout SHA256 fingerprint
 $ openssl dgst sha256 < file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Same as above.
sha256sum < file.txt
Enter fullscreen mode Exit fullscreen mode
  1. Always import fresh into git repo
 $ find . -name .git | xargs rm -rf
Enter fullscreen mode Exit fullscreen mode
  1. Hear same song repeatedly
 $ mplayer favsong.mp3 -loop 0
Enter fullscreen mode Exit fullscreen mode
  1. Watch video with vol boost, 0,9 for +,-
 $ mplayer -softvol -softvol-max 1000 file.mp4
Enter fullscreen mode Exit fullscreen mode
  1. Listen to Internet radio on command line
 $ mplayer <shoutcast url>
Enter fullscreen mode Exit fullscreen mode
  1. Resize image with ImageMagick
 $ convert file.png -resize 500x500! small.png
Enter fullscreen mode Exit fullscreen mode
  1. Find out width and height
 $ identify favicon.ico
Enter fullscreen mode Exit fullscreen mode
  1. Tell the length of media
 $ mplayer -identify -frames 0 <media>
Enter fullscreen mode Exit fullscreen mode
  1. Nuke everthing in mp3 after 90 seconds
 $ ffmpeg  -i file.mp3 -to 90 out.mp3
Enter fullscreen mode Exit fullscreen mode
  1. Get rid of first 30 seconds.
 $ ffmpeg -i file.mp3 -ss 30 out.mp3
Enter fullscreen mode Exit fullscreen mode
  1. Convert a postscript file to PDF
 $ ps2pdf14 file.ps
Enter fullscreen mode Exit fullscreen mode
  1. Create webp from png or jpg
 $ cwebp file.png -o file.webp
Enter fullscreen mode Exit fullscreen mode
  1. Change image format
 $ convert file.jpg file.png
Enter fullscreen mode Exit fullscreen mode
  1. Copy file.txt to paste buffer
 $ cat file.txt| xsel
Enter fullscreen mode Exit fullscreen mode
  1. Take screenshot from command line
 $ import f.png
Enter fullscreen mode Exit fullscreen mode
  1. Scour entire file system for files
 $ locate file
Enter fullscreen mode Exit fullscreen mode
  1. Look for pattern recursively and ignore case
 $ grep -ir pat dir/
Enter fullscreen mode Exit fullscreen mode
  1. Get rid of newline whilst printing
 $ echo -n text
Enter fullscreen mode Exit fullscreen mode
  1. Batch top output
 top -b
Enter fullscreen mode Exit fullscreen mode
  1. Show speed of download/upload
$ ifstat
Enter fullscreen mode Exit fullscreen mode

Top comments (0)