• The term Linux may mean different things to different people but in a narrow sense it refers only to the operating system kernel: the basic program that underlies everything else that communicates with the hardware (such as CPU, memory and attached devices) and the applications that run on the computer.


  • Everything else on your computer (including all the software needed to give you a nice graphical desktop) provides the full operating system to which many applications are added.


  • When people use the loosely defined term Linux System they really should be saying Linux-based System.


  • It’s a lot of work to assemble all the other components that are stacked above the Linux kernel (applications, libraries, graphical environments etc) and it is the job of a Linux Distribution to integrate all these components in a clean and updatable entity that users can take advantage of.


  • There are many different Linux distributions (sometimes called distros).


  • Whileit would be easier for the purposes of this tutorial to chose one and give instructions accordingly, we will not do that for two reasons:


  • We want you to understand what is globally true for all Linux systems and what is only true for a given family of distributions.


  • The Linux Foundation does not endorse or promote any one particular distribution since they support the community as a whole.


  • Thus we will show how things work on the following distribution families:


    1. Red Hat: Including Fedora, Red Hat Enterprise Linux (RHEL), and CentOS


    2. Debian: Including Debian, Ubuntu and Mint.


    3. SUSE: Including SUSE and OpenSUSE.


  • What unites the members of a given family is largely the method of software packaging, installation and updating.


  • In the tutorial we will use CentOS, Ubuntu and OpenSUSE as the representative members of their respective families.


  • Relatively inexperienced users may find Ubuntu or Mint easiest to get oriented with, while those used to working on more powerful hardware or so-called Enterprise systems may find CentOS or OpenSUSE easiest to grasp.


  • There are many basic command line utilities that are used to list, examine, and manipulate files and directories. Each has many options. Here is a list of very commonly used ones, that should be in any user’s toolbox:


  • Name Purpose
    ls List files
    cat Type out (concatenate) the files
    rm Remove files
    mv Rename (move) files
    mkdir Create directories
    rmdir Remove directories
    file Show file types
    ln Create symbolic and hard links
    tail Look at the tail end of the file
    head Look at the beginning of the file
    less Look at the file, one screenful at a time
    more Look at the file, one screenful at a time
    touch Either create an empty file, or update the file modification time
    wc Count lines, words, and bytes in a file
  • The find command line utility provides an extremely powerful and flexible method for locating files based on their properties, including name.


  • It does not search the interior of files for patterns, etc.; that is more the province of grep and its variations.


  •  
    $ find [location] [criteria] [actions]
     
    
  • The general form of a find command is:


  •  
    $ find [location] [criteria] [actions]
     
    
  • where there are three classes of arguments, each of which may be omitted. If no location is given, the current directory (.) is assumed; if no criteria are given, all files are displayed; and, if no actions are given, only a listing of the names is given.


  • There are many logical expressions which can be used for criteria. For example, the command:


  •  
    
    $ find /etc -name "*.conf"
     
    
  • will print out the names of all files in the /etc directory and its descendants, recursively, that end in .conf. To specify a simple action request:


  •  
    $ find /etc -name "*.conf" -ls
     
    
  • will print out a long listing, not just the names.


  • A little more complicated example is the following:


  •  
    $ find /tmp /etc -name "*.conf" -or -newer /tmp/.X0-lock -ls
     
    
  • will look in subdirectories under /etc and /tmp for files whose names end in .conf, or are newer than /tmp/.X0-lock and print out a long listing.


  • You can perform actions with the -exec option, as in:


  •  
    $ find . -name "*~" -exec rm {} ’;’
     
    
  • where {} is a fill in for the files to be operated on, and ’;’ indicates the end of the command. This can be unwieldy and one often pipes into the xargs program, as in:


  •  
     find . -name "*~" | xargs rm
     
    
  • which accomplishes the same action. A third way to do the same action would be:


  •  
    $ for names in $(find . -name "*~" ) ; do rm $names ; done
     
    
  • If a filename has a blank space in it (or some other special characters), some of the previous commands will fail.


  • It is generally a disfavored practice to utilize such file names in UNIX-like operating systems, but it is not uncommon for such files to exist, either in files brought in from other systems, or from applications which are also used in other systems.


  • In such a case, the following variant will work just fine:


  •  
    
    $ find . -name "*~" -print0 | xargs -0 rm
    
     
    
  • as will the command that uses -exec rm {} ’;’.


  • There are many options to find, especially regarding selection of files to display. This can be done based on size, time of creation or access, type of file, owner, etc. A quick synopsis is provided by find --help:


  •  
    
    user@debian:$ find --help
    Usage: find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]
    
    default path is the current directory; default expression is -print
    expression may consist of: operators, options, tests, and actions:
    operators (decreasing precedence; -and is implicit where no others are given):
          ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2
          EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2
    positional options (always true): -daystart -follow -regextype
    
    normal options (always true, specified before other expressions):
          -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
          --version -xdev -ignore_readdir_race -noignore_readdir_race
    tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
          -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
          -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
          -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
          -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
          -readable -writable -executable
          -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
          -used N -user NAME -xtype [bcdpfls]      -context CONTEXT
    
    actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print 
          -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
          -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
          -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;
    
    Valid arguments for -D:
    exec, opt, rates, search, stat, time, tree, all, help
    Use '-D help' for a description of the options, or see find(1)
    
    Please see also the documentation at http://www.gnu.org/software/findutils/.
    You can report (and track progress on fixing) bugs in the "find"
    program via the GNU findutils bug-reporting page at
    https://savannah.gnu.org/bugs/?group=findutils or, if
    you have no web access, by sending email to <[email protected]>.
     
    
  • Another method of locating files is provided by the locate command, which searches your entire filesystem (except for paths which have been excluded) and works off a database that is updated periodically with updatedb. Thus, it is very fast.


  • Thus, the command:


  •  
    $ locate .conf
     
    
  • will find all files on your system that have .conf in them.


  • A quick synopsis is provided by locate --help:


  •  
    
    user@debian:~$ apt-get install locate
    
    user@debian:~$ su root
    Password: 
    root@debian:/home/user# apt-get install locate
    
    
    root@debian:/home/user# locate --help
    Usage: locate [-d path | --database=path] [-e | -E | --[non-]existing]
          [-i | --ignore-case] [-w | --wholename] [-b | --basename] 
          [--limit=N | -l N] [-S | --statistics] [-0 | --null] [-c | --count]
          [-P | -H | --nofollow] [-L | --follow] [-m | --mmap] [-s | --stdio]
          [-A | --all] [-p | --print] [-r | --regex] [--regextype=TYPE]
          [--max-database-age D] [--version] [--help]
          pattern...
    Please see also the documentation at http://www.gnu.org/software/findutils/.
    You can report (and track progress on fixing) bugs in the "locate"
    program via the GNU findutils bug-reporting page at
    https://savannah.gnu.org/bugs/?group=findutils or, if
    you have no web access, by sending email to <[email protected]>.
     
    
  • locate will only find files that were already in existence the last time the database was updated. On most systems, this is done by a background cron job, usually daily. To force an update, you need to do:


  •  
    $ sudo updatedb