SSH Command in Linux with examples

Files and folders commands in Linux

Move around, create, copy, rename and delete files and folders. These are the commands you will type every single day.

#pwd

Show the folder you are in

Syntaxpwd
  • pwd

    Print the full path of the current folder, for example /home/deploy

  • pwd -P

    Print the real path, with any symbolic links resolved

#ls

List files and folders

Syntaxls [options] [path]
  • ls

    List the names in the current folder

  • ls -lah

    Long list with permissions, owner, human-readable sizes and hidden files

  • ls -lt

    Newest files first

  • ls -lS /var/log

    Biggest files first in /var/log

  • ls -d */

    Show only the folders

TipThe letters mean: l = long, a = all (including hidden files that start with a dot), h = human-readable sizes.

#cd

Change folder

Syntaxcd [folder]
  • cd /var/www

    Go to an absolute path

  • cd ..

    Go up one level

  • cd ~

    Go to your home folder (typing just cd does the same)

  • cd -

    Jump back to the folder you were in before

#mkdir

Create a folder

Syntaxmkdir [options] name
  • mkdir backups

    Create one folder

  • mkdir -p projects/site/css

    Create a whole chain of folders at once; no error if they already exist

  • mkdir -m 700 private

    Create a folder only you can open

#rmdir

Remove an empty folder

Syntaxrmdir folder
  • rmdir old-logs

    Remove the folder only if it is empty

  • rmdir -p a/b/c

    Remove c, then b, then a (each must be empty)

#touch

Create an empty file or update a file's time

Syntaxtouch file
  • touch notes.txt

    Create notes.txt if it does not exist

  • touch -d "2026-01-31 10:00" report.txt

    Set the modified time to a chosen date

#cp

Copy files and folders

Syntaxcp [options] source destination
  • cp report.txt report-backup.txt

    Copy a file

  • cp -r site site-backup

    Copy a folder and everything inside it (-r means recursive)

  • cp -a /etc/nginx /backup/nginx

    Copy and keep permissions, owners and dates (archive mode)

  • cp -i *.conf /etc/app/

    Ask before replacing any existing file

#mv

Move or rename

Syntaxmv [options] source destination
  • mv old.txt new.txt

    Rename a file

  • mv report.txt /srv/reports/

    Move a file to another folder

  • mv -n *.log archive/

    Move, but never overwrite files that already exist there

#rm

Delete files and folders

Syntaxrm [options] file
  • rm temp.txt

    Delete one file

  • rm -i *.tmp

    Ask before each delete

  • rm -r old-site

    Delete a folder and everything inside it

  • rm -rf build

    Force-delete without asking (be careful)

CarefulThere is no recycle bin on Linux. rm cannot be undone, and rm -rf with a wrong path can wipe a server. Read the command twice before you press Enter.

#ln

Create links (shortcuts)

Syntaxln -s target link-name
  • ln -s /var/www/site current

    Create a symbolic link named current that points to /var/www/site

  • ln file.txt hardlink.txt

    Create a hard link (a second name for the same data)

#tree

Show folders as a tree

Syntaxtree [options] [path]
  • tree -L 2

    Show two levels deep

  • tree -a -I node_modules

    Include hidden files but skip node_modules

TipIf tree is missing, install it with your package manager (for example sudo apt install tree).

#stat

Show detailed file information

Syntaxstat file
  • stat index.html

    Size, owner, permissions and all three timestamps

  • stat -c '%a %U %n' *

    Print just the permission number, owner and name for each file

#file

Find out what kind of file it is

Syntaxfile name
  • file photo.jpg

    Says "JPEG image data" even if the name is misleading

  • file /bin/ls

    Says it is an executable program

#basename

Get the file name from a path

Syntaxbasename path [suffix]
  • basename /var/log/syslog

    Prints syslog

  • basename photo.jpg .jpg

    Prints photo

#dirname

Get the folder part of a path

Syntaxdirname path
  • dirname /var/log/syslog

    Prints /var/log

#realpath

Show the full absolute path

Syntaxrealpath path
  • realpath ../logs/app.log

    Resolves .. and links into one full path

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