• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Cli intro

Cli intro






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Cli intro Cli intro Presentation Transcript

    • Introduction to the Linux Command Line Interface Prepared for NSLUGS by Corrie Watt October 2013
    • The Linux CLI CLI = Command Line Interface “Graphical user interfaces make easy tasks easy, while command line interfaces make difficult tasks possible.” (original source unknown)
    • Getting Started Launch the terminal emulator me@linuxbox: ~$ Type in some stuff me@linuxbox: ~$ lkjerxv Press Enter bash:lkjerxv: command not found me@linuxbox: ~$ Up-arrow for history: shows previous commands used Cursor movement by arrows: go forward, backward in a line of text File names in Linux are case sensitive: file root is not file Root
    • Some Simple Commands Display current time and date or this month's calendar: me@linuxbox: ~$ date me@linuxbox: ~$ cal See the current amount of free space on your disk drives: me@linuxbox: ~$ df See amount of free memory: me@linuxbox: ~$ free Ending a terminal sesssion: me@linuxbox ~$ exit
    • Navigating the File System Files in Linux are hierarchical (in an upside-down tree structure) A file may contain data in some format (such as .jpg, .pdf, .txt, .php), or it may contain other files, in which case it is a directory. Directories are files that contain files: sub-directories and data files (eg. Downloads, home, Recipes). For command line navigation, we need to know what directory we are currently in, so that we can navigate to where we want be: me@linuxbox: ~$ pwd /home/me me@linuxbox: ~$
    • Working with Directories Print my current (working) directory me@linuxbox: ~$ pwd /home/me List the files in the current directory me@linuxbox: ~$ ls 2013-14Courses beta.tgz Desktop (etc.) Change the working directory using Absolute Pathnames me@linuxbox: ~$ cd /usr/bin me@linuxbox:/usr/bin$ Change the working directory using Relative Pathnames me@linuxbox:/usr/bin$ cd .. me@linuxbox:/usr$
    • Navigation Shortcuts (not all of these work in all Linux distros) cd Changes the working directory to your home directory cd - Changes the working directory to the previous working directory cd ~jane Changes the working directory to user Jane's home directory More fun: Get more information about each file by using the -l option: me@linuxbox: ~$ ls -l drwxr-xr-x 2 jane users 4096 May 2 2011 c_scripts -rw-r--r-- 1 jane users 2313 Sep 21 2012 dvd-vids.html Type of file (d or -), permissions: read, write, execute (owner, group, world) File's number of hard links, name of owner, group, size of file in bytes Date and time of file's last modification, name of the file Use the file option to get the file's type: me@linuxbox: ~$ file pizza-whatever pizza-whatever: ASCII text, with very long lines
    • Less is More The less program is an improved replacement of the earlier Unix program called more. Many Linux files have human-readable text content, and less lets you look at them. It allows paging forward and backward, as well as many other things. It is very useful for reading the actual programs (scripts) the system uses and for checking out what is in the system configuration files. Sample less commands: PAGE UP or b Scroll back one page. PAGE DOWN or spacebar Scroll forward one page. Up Arrow; Down Arrow Scroll up one line, scroll down one line. G Go to end of text file. g Go to the beginning of the text file. /characters Search forward to the next occurrence of characters. n Search for the next occurrence of the previous search. H Display help screen q Quit less
    • The Linux File System Directory Description / The root directory (where everything begins) /bin Contains programs the system requires to boot and run /boot Contains the Linux kernel, initial RAM disk image, and boot loader /dev Here the kernel keeps a list of all the devices it understands; contains device nodes. Each device is treated as a file. /etc Contains system-wide configuration files (all human readable); see /etc/passwd to see a list of all user accounts. /home Each user is given a directory in /home, and is usually limited to writing to files only in their home directory, to protect the system. /lib Contains shared libraries used by the core system programs. /lost+found Each formatted partition or device using the file-system, eg. ext3, will have this directory. It is used in case of a partial recovery from a file-system corruption event. In good times, it is empty. /media, /mnt Contain mount points for removable media (USB drives, etc.) /opt Mainly used to hold commercial software products installed on your system. /proc A virtual file-system that gives a glimpse into the kernel. /root This is the home directory for the root account.
    • The Linux File System (continued) Directory Description /sbin Programs that perform vital system tasks; superuser access only. /tmp Used for storing transient files created by various programs; may be emptied upon reboot. /usr This directory contains all the programs and support files for regular users. /usr/bin Contains executable programs installed by your Linux distribution. /usr/lib The shared libraries for the programs in /usr/bin. /usr/local Here is where programs for use by the system but not part of the Linux distribution are stored. /usr/sbin More system administration programs. /usr/share Shared data used by programs in /usr/bin, including default configuration files, icons, screen backgrounds, etc. /usr/share/doc Documentation files for packages installed on the system. /var The files in /var tend to change a lot: databases, spool files, user mail, etc. /var/log Contains log files of system activity; should be looked at occasionally for signs of system problems.
    • Doing Things with Files Copy files and directories (there are options with cp, too) cp -i myfile1 myfile2 cp myfile1 myfile2 myfile3... destination_directory cp -u *.mp3 destination_directory --- easy in the CLI! Move/rename files and directories mv file1 file2 mv file1 dest_directory Create new directories mkdir directory... Remove (delete) files and directories rm -i item... rm -r directory... rm -i *.jpg (rm -r * ~ WATCH OUT!)
    • Commands A command can be: An executable program (like the files in /usr/bin). It can be a shellscript, a compiled program (in C or C++), or a script in Perl, Python, Ruby, etc. A shell function (miniature shell scripts that are part of the environment). A command built into the shell (ls, cd, etc.). An alias – a command we can define, which I will not cover here. What type of command am I using? Use this to find out what type your command is: me@linuxbox: ~$ type cp cp is /bin/cp Help! There is on-board documentation for all shell built-ins in your help files: me@linuxbox: ~$ help cd cd: cd [-L| -P] [dir] ...and a whole lot of information about cd
    • More Help... For executable programs, you can display usage information by using the --help option that is part of the command's syntax. me@linuxbox: ~$ mkdir --help Usage: mkdir [OPTION] DIRECTORY... Create the DIRECTORY(ies), if they do not already exist...etc. Executable programs that are usable from the command line usually have a manual (“man page”) available. The program man lets you scroll through them. (Usually, man uses less to display the man pages). me@linuxbox: ~$ man ls (This will display the man page, which is broken into sections 1-8, where section 1 contains the user commands.) The whatis program will provide you with a one-line description of a command. me@linuxbox: ~$ whatis cat cat (1) - concatenate files and print on the standard output Note: You will find readable documentation files for many of the software packages installed on your system in the /usr/share/doc directory. Most are in plaintext format; some may be in HTML format and can be opened in a browser.
    • Echo ... Echo ... Echo Echo is a shell command that displays a line of text. me@linuxbox: ~$ echo Hello World Hello World me@linuxbox: ~$ echo * Desktop Documents Downloads medusa1.php xplanet-gnome-output.txt mybooks Since the wildcard character * means “match any characters in a file name”; the shell expands the * into something else before the echo command is executed. We get a display of the contents of our current working directory! me@linuxbox: ~$ echo D* Desktop Documents Downloads me@linuxbox: ~$ echo *s Documents Downloads mybooks me@linuxbox: ~$ echo ~ /home/me me@linuxbox: ~$ echo ~jane /home/jane
    • A copy of these slides is available at: http://www.slideshare.net/corriewatt9/cli-intro-26416362 That's all for now! Thank You