All Projects β†’ arturoherrero β†’ Command Line One Liners

arturoherrero / Command Line One Liners

Command line one-liners.

Programming Languages

bash
514 projects

Projects that are alternatives of or similar to Command Line One Liners

Laravel Desktop Notifier
πŸ’» Send notifications to your desktop from your Laravel Artisan Commands. An JoliNotif wrapper for Laravel.
Stars: ✭ 333 (-10.48%)
Mutual labels:  command-line
Gandi.cli
command line interface to Gandi.net products using the public API
Stars: ✭ 349 (-6.18%)
Mutual labels:  command-line
Bulksplash
A simple command line tool that lets you bulk download images from Unsplash
Stars: ✭ 362 (-2.69%)
Mutual labels:  command-line
Vergeml
Machine Learning Environment - alpha version
Stars: ✭ 338 (-9.14%)
Mutual labels:  command-line
Tv
Quickly view (satellite) imagery directly in your terminal using Unicode 9.0 characters and true color.
Stars: ✭ 347 (-6.72%)
Mutual labels:  command-line
Facebook Cli
πŸ’» Facebook command line tool
Stars: ✭ 350 (-5.91%)
Mutual labels:  command-line
Bcal
πŸ”’ Storage and general-purpose calculator
Stars: ✭ 329 (-11.56%)
Mutual labels:  command-line
T2b
A wicked-powerful text macro language for building binary files.
Stars: ✭ 370 (-0.54%)
Mutual labels:  command-line
Gulp Cli
Command Line Interface for gulp.
Stars: ✭ 347 (-6.72%)
Mutual labels:  command-line
Speedtest
Command line client for speedtest.net written in Go
Stars: ✭ 361 (-2.96%)
Mutual labels:  command-line
Bfs
A breadth-first version of the UNIX find command
Stars: ✭ 336 (-9.68%)
Mutual labels:  command-line
Cmd2
cmd2 - quickly build feature-rich and user-friendly interactive command line applications in Python
Stars: ✭ 342 (-8.06%)
Mutual labels:  command-line
Reminders Cli
A simple CLI for interacting with macOS reminders
Stars: ✭ 354 (-4.84%)
Mutual labels:  command-line
Towel
Throw in the towel.
Stars: ✭ 333 (-10.48%)
Mutual labels:  command-line
Terminal Link
Create clickable links in the terminal
Stars: ✭ 361 (-2.96%)
Mutual labels:  command-line
Go Tea
Tea provides an Elm inspired functional framework for interactive command-line programs.
Stars: ✭ 329 (-11.56%)
Mutual labels:  command-line
Sad
CLI search and replace | Space Age seD
Stars: ✭ 350 (-5.91%)
Mutual labels:  command-line
Kondo
Save disk space by cleaning non-essential files from software projects.
Stars: ✭ 373 (+0.27%)
Mutual labels:  command-line
Jwt Cracker
Simple HS256 JWT token brute force cracker
Stars: ✭ 365 (-1.88%)
Mutual labels:  command-line
Tsukae
πŸ§‘β€πŸ’»πŸ“Š Show off your most used shell commands
Stars: ✭ 345 (-7.26%)
Mutual labels:  command-line

Command line one-liners

After my article about command line one-liners, many people want to contribute with their own commands. This is the place to do it, pull requests are welcome!

Table of Contents


History

  • Run the last command

    $ !!
    
  • Run the last command as root

    $ sudo !!
    
  • Create a script of the last executed command

    $ echo "!!" > script.sh
    
  • Reuse all parameter of the previous command line

    $ echo cd .
    $ !*
    
  • Run the last command with some argument

    $ echo a b c d e
    $ echo !!:2
    $ echo !!:3-$
    
  • Insert the last argument of the previous command

    $ cp script.sh /usr/bin/
    $ cd !$
    $ cd <ESC> .
    $ cd <ALT> .
    
  • Runs previous command but replacing

    $ echo no typos
    $ ^typos^errors
    
  • Escape any command aliases

    $ alias ls="ls -a"
    $ \ls
    
  • Run a command from the history

    $ history
       ...
       1225  ls -l
       1226  git status
       1227  history
    $ !-3
    $ !1225
    
  • Search the history for the most recent command beginning with text

    $ !text
    
  • Search the history for the most recent command containing text

    $ <ctrl-r>text
    
  • List of commands you use most often

    $ history | awk '{print $2}' | sort | uniq -c | sort -rn | head
    
  • Execute a command without saving it in the history

    $ <space>command
    

Directories

  • Make a directory creating intermediate directories

    $ mkdir -p a/long/directory/path
    
  • Create a directory and change into it

    $ mkdir dir && cd $_
    
  • Change to the previous working directory

    $ cd -
    
  • Jump to a directory. Execute a command in a subshell. Jump back to current directory

    $ (cd /tmp && ls)
    

Files

  • Quickly rename a file

    $ mv filename.{old,new}
    $ mv filename.{png,jpg}
    
  • Create a quick back-up copy of a file

    $ cp file.txt{,.bak}
    
  • Create a simple text file from command line

    $ cat > file.txt
    {your text here}
    {your text here}
    <ctrl-d>
    
  • Create a simple text file from command line or script (EOF is just a token, can be any word)

    $ cat > file.txt << EOF
    {your text here}
    {your text here}
    EOF
    
  • Empty a file from command line (usefull to truncate log file from running processes)

    $ > file.txt
    
  • Empty a file from command line or script

    $ cat /dev/null > file.txt
    
  • Make less behave like tail -f

    $ less +F somelogfile
    
  • Display line numbers in a file

    $ cat -n file
    $ less -N file
    
  • Redirect standard input to a file. Print it to standard output

    $ command | tee file.txt | less
    
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚ command │─▸│   tee   │─▸│ stdout  β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ύ
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   file    β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    

Searching

  • Search for a string inside all files in the current directory

    $ grep -RnsI --color=auto <pattern> *
    
  • Beyond grep

      _   /|
      \'o.O'
      =(___)=
        U    ack!
    
    $ ack <pattern>
    
  • Recursively remove all empty directories

    $ find . -type d -empty -delete
    

Networking

  • Serve current directory tree at http://$HOSTNAME:8000/

    $ python -m SimpleHTTPServer
    $ ruby -run -e httpd . -p 8000
    
  • Share a file between two computers

    receiver $ nc -l 5566 > data-dump.sql
    sender   $ nc <receiver-ip-address> 5566 < data-dump.sql
    
  • Share a BIG file between two computers and show progress bar

    receiver $ nc -l 5566 > big-file.iso
    sender   $ pv big-file.iso | nc <receiver-ip-address> 5566
    
  • Transfer a folder between two computers

    receiver $ nc -l 5566 | tar -zxv
    sender   $ tar -zcv <folder> | nc -w1 <receiver-ip-address> 5566
    
  • Download an entire website

    $ wget -m -k http://website.com
    

User environment

  • Show PATH in a human-readable way

    $ echo $PATH | tr ':' '\n'
    $ tr ':' '\n' <<< $PATH
    
  • Clear the terminal screen

    $ <ctrl-l>
    $ clear
    
  • Salvage a borked terminal

    $ reset
    
  • Close shell keeping all subprocess running

    $ disown -a && exit
    
  • Run a command immune to hangups

    $ nohup command &
    

Networking

  • Attach screen over ssh

    $ ssh [email protected] -t screen -r
    
  • Compare a remote file with a local file

    $ ssh [email protected] cat /path/to/remotefile | diff /path/to/localfile -
    
  • Get your public IP address

    $ curl ifconfig.me
    
  • Set audible alarm when an IP address comes online

    $ ping -a IP_address
    
  • List programs with open ports and connections

    $ lsof -i
    
  • Check which process is listening on a specific port

    $ netstat -nlp | grep 8080
    $ netstat -nlp tcp | grep 8080 (BSD)
    

File system

  • Currently mounted filesystems in nice layout

    $ mount | column -t
    
  • Display free disk space

    $ df -h
    
  • Display disk usage statistics for the current directory

    $ du -sh *
    
  • Display 10 biggest files/folders for the current directory

    $ du -s * | sort -nr | head
    
  • Create a zip archive of a directory

    $ zip -r archive.zip directory
    
  • Extract compressed archive

    $ unzip archive.zip
    
  • Show File System Hierarchy

    $ man hier
    

Date & Time

  • Shutdown the system at a given time

    $ shutdown -h now
    $ shutdown -h 22:49
    
  • Execute a command at a given time

    $ echo "ls -l" | at midnight
    
  • Simple stopwatch

    $ time read
    <ctrl-d>
    
  • Put a console clock in top right corner

    $ while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done &
    
  • Displays a calendar

    $ cal 12 1984
    
  • What day was yesterday or will it be tomorrow, etc...

    $ date -d yesterday
    $ date -d tomorrow +%Y-%m-%d
    $ date -d "7 days ago" +%Y-%m-%d
    $ date -j -v-1d (BSD)
    

Processes

  • Display the top ten running processes. (Sorted by memory usage)

    $ ps aux | sort -nk +4 | tail
    
  • Kill all Ruby processes

    $ ps aux | grep ruby | awk '{ print $2 }' | xargs kill -9
    $ ps aux | awk '/ruby/ && ! /awk/ { system("kill -9 "$2) }'
    $ pkill -f ruby
    $ killall -9 ruby
    
  • Check which process is modifying a certain directory or file

    $ auditctl -w /path/to/directory -p war
    

    See results

    $ ausearch -f /path/to/directory
    

Miscellaneous

  • 32 bits or 64 bits?

    $ getconf LONG_BIT
    
  • Quick access to the ascii table

    $ man ascii
    
  • Count your commits

    $ git shortlog -sn
    
  • Russian Roulette in Bash (remember kids don't try this at home)

    $ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live"
    
  • Watch Star Wars via telnet

    $ telnet towel.blinkenlights.nl
    

Who made this?

This was made by Arturo Herrero under the MIT License. Find me on Twitter @ArturoHerrero.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].