SSH Command in Linux with examples

Reading and editing text commands in Linux

Look inside files, follow growing log files and edit text from the terminal.

#cat

Print a file

Syntaxcat file [file2 ...]
  • cat notes.txt

    Print the whole file

  • cat -n script.sh

    Print with line numbers

  • cat a.txt b.txt > all.txt

    Join two files into a new file

#less

Read a long file page by page

Syntaxless file
  • less /var/log/syslog

    Open a log; use arrows or Space to move, / to search, q to quit

  • less +F app.log

    Open and follow new lines as they arrive (Ctrl+C to stop following)

Show the first lines

Syntaxhead [-n N] file
  • head -n 5 data.csv

    First five lines

  • head -c 100 file.bin

    First 100 bytes

#tail

Show the last lines

Syntaxtail [-n N] file
  • sudo tail -n 50 /var/log/nginx/error.log

    Last 50 lines (most files in /var/log need sudo)

  • sudo tail -f /var/log/syslog

    Keep watching new lines as they are added (Ctrl+C to stop)

  • tail -F app.log

    Same, but keeps going if the log is rotated

#nano

Simple text editor

Syntaxnano file
  • nano /etc/hosts

    Open a file (use sudo for system files)

TipCtrl+O saves, Ctrl+X exits, Ctrl+W searches. The shortcuts are listed at the bottom of the screen.

#vim

Powerful text editor

Syntaxvim file
  • vim config.yml

    Open a file. Press i to type, Esc to stop typing

  • vim +42 app.py

    Open at line 42

TipTo leave Vim: press Esc, then type :wq and Enter to save and quit, or :q! to quit without saving.

#tee

Show output and save it too

Syntaxcommand | tee file
  • ls -l | tee list.txt

    Print the list and also write it to list.txt

  • echo "127.0.0.1 test" | sudo tee -a /etc/hosts

    Append a line to a root-owned file (plain > would fail)

#wc

Count lines, words and bytes

Syntaxwc [-l] [-w] [-c] file
  • wc -l access.log

    Count lines

  • ls | wc -l

    Count how many files are in the folder

#nl

Number lines

Syntaxnl file
  • nl script.sh

    Print the file with numbered lines

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client