Linux CLI

Command Line Interface Reference

Tutorials

Quod erat demonstrandum (QED)[1]

Command Examples

While doing web site development.

  • Find a file or directory
  • Tar or Unzip archive and compression/decompression
  • wget files from the web
  • sshremote secure login

System administration

  • Set the users default editor to nano.
  • Add user to sudo group

Open: Command Line Interface, Tutorials, or Examples

My examples of CLI commands:

Find a file:


# Find in the directory specified by the system variable
# $HOME and all directories contained in that directory
# a file named 'index.' with any suffix specified by the
# wildcard character '*'
find $HOME -name index.*


Find a word in a file. For example an error message lists the culprit as myFunctionCall. Where in the directories is that function defined, and where is it called from?


# Find in the directory specified by the system variable
# $HOME and all directories contained in that directory
# a file named '.php' with any prefix specified by the
# wildcard character '*' that contains the word
# 'myFunctionCall'
find $HOME -name '*.php' -print0 | xargs -0 grep -l myFunctionCall


tar Decompress and unarchive files

# Decompresses the specified archive, for example
# 'jquery_plugin-7.x-1.0.tar.gz',  and extracts
# the files into the current working directory
# Identify which directory you are in
# with the 'pwd' command.
tar -xvzf jquery_plugin-7.x-1.0.tar.gz


Archiving and compressing a directory


# Create an archive file named, for example
# 'drupal_020915.tar.gz',  and run it through
# gzip compression.  The target directory to
# be archived is 'd' in this case. (note no '-'
# preceeds the options)
tar cvzf drupal_020915.tar.gz d/


Unzipping compressed files with the '.zip' extension into the current working directory.


unzip -v jquery.jqGrid-4.6.0.zip


wget Download files or even multiple linked pages from the web.

# Download the file specified in the path
# 'http://ftp.drupal.org/files/projects/drupal-7.33.tar.gz',
# into the current working directory
# Before issuing the wget command, identify which
# directory you are in with the 'pwd' command.
# -p get all files
wget -p http://ftp.drupal.org/files/projects/drupal-7.33.tar.gz


If you are writing some code to scrape data from a web page you can be nice while debugging your code and work on a downloaded local copy on your server.


wget -p http://thetargetedserver.org/thelist.html

# -r
#  The -r option recursively follows and retrieves all links
#  on the specified site.
wget -r http://thetargetedserver.org/sitemap.html

ssh Secure shell login to a remote server, Open ssh is the free version of the connectivity tool. Some ssh examples.

#Login to a remote host on which you have an account under a different user name than the host you're currently logged into:
ssh myLoginName@the.server.com

#or with an IP number and no URL.  Where 192.168.1.1 is an example placeholder for the IP number of your server.  Put your IP number in the placeholder.
ssh myLoginName@192.168.1.1

Set users default editor to nano (from the typical vi system default)


  $ cd ~ # users home directory
  $ which nano   # returns the location of the command
/user/bin/nano # here for example $ nano .bashrc
  • In the .bashrc file append the following two lines

  # User specific aliases and functions
  export EDITOR=/usr/bin/nano
  • exit nano
  • logout of your terminal
  • logout of your regular user session
  • as a test log back in and  open a terminal to run a command that opens the default editor