Basic Shell Commands
Command | Description |
---|---|
mkdir dirname | create a directory |
mkdir -p dirname/dir2name | make both even if 1st doesn't exist |
touch filename > filename | create a blank file |
rm | delete file or directory |
rm -r rm -R | recursively (mandatory for directory) |
rm -i | request info before each deletion |
rm -f | force deletion example: rm -Rf images/misc/ file* deletes both images/misc/ and all files in current directory starting with “file” |
mv | rename or move files |
mv -f | force, no warning if overwrite |
mv -i | ask before overwrite |
mv -v | verbose, report all changes example: mv foo bar rename foo to bar example: mv -vf file* images/ trash/ move without requesting confirmation, all files that start with “file” and the images directory to trash |
cp | copy files and directories |
cp -R | recursive copy, mandatory for directory, even if empty |
cp -i | request confirmation |
cp -f | force w/o confirmation |
cp -v | verbose mode example: cp -vR docs/ /shared/mp3s/* /mystuff/ copies whole docs dir, with all files in /shared/mp3s/ to /mystuff/ |
ls | listing files (like dir command in DOS) |
ls -l | additional info |
ls -a | all files including hidden |
ls -R | recursive |
ls -s | display file size |
ls -i | displays inode # |
ls -d | displays directories as normal files instead of contents |
cd | change directory |
cd .. | change one directory higher (up) |
cd ../../ | change two directories higher (up) |
cd ../../somedir/ | change to somedir, which is located two levels higher than the current directory |
cd - | change to last directory you were in |
cd ~john | change to john's home directory |
cd, cd ~, or cd ~/ | change to your home directory |
other | |
cat | print the contents of one or more files to the screen; also used for device detection like a mouse |
su | temporarily login as another user (usually root - shell turns to #) actually means “substitute user” |
Searching for files
which <command> | locate a command |
locate <file> | searches a file index for files (faster) |
updatedb | updates the file index so the locate command has an updated listing |
find | does an actual search for files (slower) |
examples:
find /usr -name spell -print A | B | C | D * A - location * B - name switch (-iname is case insensitive) * C - filename * D - not necessary - used by default now
(find all files modified within the last 24 hours) find -mtime -1
find /usr -name '*.ps' -print -xdev A | | B * A - search pattern * B - only search linux filesystems
find / -iname '*.ps' -print
which ps2pdf - find the ps2pdf command location
locate *.ps - search locate database for all .ps files
* See the find man pages for many more options