Quick Guide to CLI Commands

Danny Brito
3 min readNov 14, 2019

--

The command line interface (CLI) is a text-based user interface used to view and manage computer files.

We are able to interact with the CLI by writing commands.

Most essential and basic commands:

List (ls): outputs directory content

Change Directory(cd): navigates between directories

Print Working Directory (pwd): If you are not sure where you are located, you can print the absolute path to your home directory

These commands can be used along with different arguments/flags

(Note: you can combine different flags within the same command. For example: ls -la)

ls

  • No flag: it will output all the files within directory
  • -a: it will display all files & any hidden files
  • -l: it will print files in a long list format

cd

  • cd directory_name/ will move you into the specify directory
  • cd by itself will return you to home directory (~)
  • cd .. will move you back one directory
  • cd path/other/extended you can move through

Moving, copying, creating, renaming files on CLI

$cp - Copy File
$mv - Move File - Rename Files
$touch - Change file access and modification times
$mkdir - Make Directory

mkdir

  • Use to create a new directory as mkdir NewDirectory
  • -p (flag): mkdir -p will allow you to create multiple nested directories by specifying a path => mkdir -p First_directory/other/here/one_more

cp

  • cp file_to_copy path/where/you/want/to/save/the_copy.extension if existent

mv

  • mv file_to_move path/where/you/want/to/move/file.extension if existent — you can rename the file by last argument in the path => mv Test.txt ./new/path/Rename_test.txt

touch

  • We can use touch to create a new file

Removing Files & Directories

$rm - remove file
$rmdir - remove directory

Warning! Use these commands with caution as rm is permanent and will destroy the files. They will not be sent to the recycle bin!

rm

  • specify file to delete, rm file_to_delete
  • -r(flag): remove a directory
  • -f(flag): forceful remove

rmdir

  • use rmdir to delete an empty directory as rmdir folder/

There are many commands for the CLI out there. Two more useful commands to know are:

$man command_name // Ex: $man ls
$whatis command_name // Ex: whatis ls

man - It will show the manual page for a specific command. Use up & down keys to navigate the manual. Hit ‘q’ to exit out the manual.

whatis - It will print a description of utility for the command.

Bonus:

If you ever need to kill a process running in your computer (for example, if you need to force down a process running in a port), you can do the following:

  1. run command ps (print processes)
  2. it will list the processes happening in the computer - it will display the PID(number to identify process) and the process itself
  3. run command kill <PID> use correct PID for the process to be shut down If the process does not end, you could use the flag: -9 to force close the process.

--

--