Linux Commands

I suppose that I use about 15 commands to do 90% of what I need.

 

Glossary of Key terms

Linux Glossary
command brief description
pwd print the location of the working directory (WD)
env display the environment variables in the current shell
ls list files and directories in the WD
mkdir X make a new directory named X
cd Change directory to the user HOME (denoted ~/)
cd X Change to directory X
cd .. Change directory above the WD
exit log out
find . -iname "*.R" Beginning in the WD, list all files ending in ".R" or ".r"
grep disaster * Search in the WD for any files that have the word disaster in them.
cat myfile.R Print out the contents of myfile.R on the screen
cat myfile.R | grep disaster Print myfile.R, but only lines with word "disaster"
qxlogin When on login2.acf.ku.edu, ask for a terminal session on a compute node. The "x" signifies that the session will include the X11 graphics display capability. Can display a GUI program running in one computer on another computer's display.
qlogin Same as qxlogin, but does not request the X11 graphics display.
   

 

 

Please don't forget that the TAB key offers "command completion," so if you type the first few letters of a long file name, the TAB key will complete it for you.

1. cd stands for "change directory"

1. take user to own home

$ cd     

2. same

$ cd ~  

( ~/ refers to home on all varieties of Unix or Linux that I know of ).

3. if currently in home, go into "whatever" directory

$ cd whatever

4. if currently elsewhere, take user to "whatever" directory inside home

$ cd /home/username/whatever 

5. same as

$ cd ~/whatever

6. move up one level in directory hierarchy

$ cd ../

7. move up two levels

$ cd ../../

2. ls is for listing directory contents

$ ls # lists files

$ ls -l # lists files with detailed information $ ls -a # lists both hidden (start with dot) and nonhidden files $ ls -la # shows combination of options $ ls -la p* #If you need to see only files that start with "p" $ ls -s1 # show file sizes, one file per line (thats a number 1 after s) $ ls --color=yes # output is color coded by file type $ man ls # shows the manual for the ls command

Example:

$ ls -la

drwxrwxr-x 3 pauljohn pauljohn 4096 Dec 11 2001 valinux

-rw-rw-r-- 1 pauljohn pauljohn 5496 Nov 14 2001 unemployment.html


The permissions for each are displayed. The first one is a directory, which you can see by the d in the first character. The second is a file.

 

3. rm will remove things

$ rm aFileName.whatever # erase "aFileName.whatever"
$ rm -rf aDirectory # erase everything in aDirectory

4. mkdir creates a directory

$ mkdir aDirectory # create "aDirectory"
$ mkdir -p aDirectory/aSubDir/aSubDir # -p allows several "layers"

5. mv will move or rename a file or directory.

6. cat displays the contents of text files to the screen.

$ cat aFile.txt # shows all lines from aFile.txt

This is faster than opening a file in an editor. Also safer because there's no danger of accidentally changing the file.

7. grep scans outputs for particular patterns

Grep is almost always used in conjunction with the pipe "|" operator. The pipe is a connector between two actions, usually thought of as "sending" one thing's output to another thing.

$ cat aFile.txt | grep catpoop # display lines only if they have "catpoop"

8. find recursively searches for files

$ find . -name "*crud*" 

Under the current working directory ("."), search recursively through all subfolders to list all filenames that include the letters "crud" (capitalization counts!)

$ find /usr/bin -name "fire*"

Under /usr/bin, find all files beginning with fire.

$ find /sbin -iname "*what*"

Under /sbin, list all files that have letters "what" but ignore capitalization.


find is the way that cool guys like me (old school guys) locate stuff. Youngsters sometimes rely on system-specific functions like "locate" or "slocate", but find has never failed me. Find seems to always work for me, it is available on every Unix/Linux system, and it has some super cow powers! For example, it can execute commands on files:

$ find ~/ps/ps110 -iname "Test*.odt" --exec oowriter {} \;

That will scan for all Open Office document files that begin with "Test" and open them up with Open Office's word processor Writer.

9. tar groups together files into packages, "tarballs"

"tar" originally stood for "tape archiver" but now it serves a much more general purpose. See Tar and other Compression Systems.


CRMDA Calendar

Like us on Facebook
One of 34 U.S. public institutions in the prestigious Association of American Universities
44 nationally ranked graduate programs.
—U.S. News & World Report
Top 50 nationwide for size of library collection.
—ALA
23rd nationwide for service to veterans —"Best for Vets," Military Times
Equity & Diversity Calendar

KU Today