A place to just document useful commands and all the good stuff in the terminal I’ve found useful so far.

 

Basic Commands

CommandDescription
lsList contents (short)
ls -lList contents (long)
ls -aList contents w/ hidden files
ls -lhLong Listing with human readable file sizes
ls -RList contents recursively
cdHome directory
cd {directory}Change directory
sudo {command}Runs command as super user
sudo !!Runs sudo on previous command
topDisplays all active processes
clearClear screen
resetReset screen
qQuit

 

Shortcuts

CommandDescription
TabAutocomplete
Ctrl + CKill Process
Ctrl + DExit Shell
Ctrl + LClear Screen
Ctrl + ZPuts whatever you are running into a suspended background process. fg restores it.
Ctrl + AGo to beginning of current line
Ctrl + EGo to end of current line
Ctrl + UClears line before cursor position
Ctrl + KClears line after cursor position
Ctrl + WDeletes word before cursor

 

File System Management

CommandDescription
pwdList current working directory
touch {file}Create file
cat {file}Concatenate file and display on command line
rm {file}Remove file (permanent)
rm -rf {directory}Delete folder and its contents (Recursively force remove)
mv {file} {newFile}Move/Rename file
cp {file} {newFile}Copy to file
touch {file} {directory}Copy to folder
grep {pattern} {file}Searches file(s) for specific pattern
mkdir {directory}Create directory
rmdir {directory}Delete directory

 

Pipe
Piping is essentially chaining the outputs of a command into the input of the following command.

CommandDescription
{command} | {command}Push output of command 1 into command 2
{command} > {file}Push output to a file (overwrite)
{command} >> {file}Push output to a file (append)

Example: Grab all instances of foo from command line history

history | grep foo | less

Example: Pipe output in to grep

man curl | grep verbose

 

Flags
Flags are command line parameters appended to a command to specify certain settings, multiple flags can be used in combination. **Note -** The following examples will be based on the command “`ls“`. Flags will vary depending on the command they are affiliated with. The following examples are just “common” flags that you may or may not see in other commands.

CommandDescription
-aAll (including files starting with .)
-AAlmost all (not including files starting with .)
-dList directory entries instead of contents
-fDo not sort
-hHuman readable
-I {Pattern}Do not show entries with {Pattern}
-rReverse order
-RRecursive
-sPrint size
-SSort by size
man {command}Look up list of flags

Example: Grab all files at a specific location with a specific pattern

grep -l -f /src/bin/foo bar

 

History

CommandDescription
history nDisplay previous commands inputed (limit to n)
Ctrl + RSearch through command history
jobsList all the current jobs
!!Execute previous command

 

Job Control
Job control allows you to have multiple processes or “jobs”, essentially run by the shell. Press ctrl + z when in a program (ex – vim) to back out of it and put it into the background.

CommandDescription
Ctrl + ZBack out of program and put into background
jobsList all the current jobs
bg/fg {job}Move job to the background or foreground
kill {job}Kill a specific job

Example: Send job “top” to foreground

[1]+ Stopped top
 brandon@brandon-Inspiron-560:~$ fg "%top"

 

Networking
“`telnet“` and “`netcat“` are both networking commands for reading from and writing to network connections using TCP or UDP. “`wget“` and “`curl“` are programs that retrieve content from web servers.

CommandDescription
telnet {application}Command line interface client to TCP application
netcat {application}Better (arguably) command line interface client to TCP application
netstatLists all the TCP/UDP connections on your network
curl {URL}Retrieve URL page
wget {URL}Retrieve URL page

Examples coming soon!!!

 

Help and Documentation

CommandDescription
{command} --helpDisplay help
man {command}Display command's documentation
whatis {command}Display one line description

Other Useful Stuff
CommandDescription
>> (Heredocs)Execute all commands within these lines between the two points.
chmod +x {script}Make your bash script an executable

Example: Send a GET request to a local host

$ nc localhost 8008 << HERE > > GET /api/v0/course/all HTTP/1.0 > > HERE

Linux Safe Reset

Alt + SysRq + R E I S U B "Reboot even if system utterly broken"
Print Friendly, PDF & Email

One thought on “The Command Line

Leave a reply