A glimpse at Unix Commands
Working in a terminal shell on a command line sounds like heaven for some developer, but hell for some others. Even though I would consider myself more technical than creative, i.e. more programmer than designer, it did quite happen a lot in the past that opening a terminal window (whether it was on Mac OSX or any other Unix-based machine) caused an attack of sweating. Well, I am exaggerating. But still, when I watched “the gurus” using the command line, I was always astonished how they could all keep all the myriads of commands and options in their heads. It is just a matter of practice and experience I guess. But if you don’t have that much of an experience, like I do, the following “cheat sheet” might help to get familiar with it and keep one or the other useful command in your head for the future.
Files and Directories
Change directory
cd [directory]
Examples
- cd ~ takes you to your users home directory
Resources
Create new directory
mkdir [dirname]
Examples
- mkdir homedir creates a new directory ‘homedir’
Resources
Delete a directory
rmdir [option] [directory]
Examples
- rmdir homedir remove the directory ‘homedir’
- rm -r directory remove a directory, even if files existed in that directory
Resources
Move file f to directory d
mv f1 [f2...] d
Examples
- mv myfile.txt newdirectory/ moves the file myfile.txt to the directory newdirectory
Resources
Rename directory d1 as d2
mv d1 d2
Examples
- mv alpha beta renames directory ‘alpha’ to ‘beta’
Resources
Delete a file
rm [-f] [-i] [-R] [-r] [filenames | directory]
Examples
- rm myfile.txt removes the file myfile.txt without prompting the user
- rm -rf /tmp/* removes all files (including write-protected ones) within /tmp recursively (including directories)
Resources
List contents of directory
ls [options] [pathnames]
Examples
- ls -a shows you all files, even files that are hidden (these files begin with a dot.)
- ls -d */ only list the directories in the current directory
- ls -lsa shows additional information about files (permission, size, hidden files, blocks etc.)
- ls -1 lists the contents with one entry on each line (without any add. info)
Resources
Create symbolic link
ln -s [destination] [source]
Examples
- ln -s ~/dev/myproject/htdocs . symlinks current directory to stated directory
- ln -s /export/space/common/archive /archive create a symlink from…to… (speak: “/archive is gonna link to /export/space/common/archive”)
Resources
Environment Information
OS information
uname -a
Change password
passwd
Create command alias (csh/tcsh)
alias name1 name2
Create command alias (ksh/bash)
alias name1="name2"
Remove command alias na
unalias name1[na2...]
Login securely to remote node
ssh nd
End terminal session
exit
Set env var to value v (csh/tcsh)
setenv name v
set environment variable to value v (ksh/bash)
export name="v"
execute a file as a tcl script
source
Examples
- source ~/.profile executes .profile in user home directory
Search
Search for Text in Files
grep [options] PATTERN [FILE...]
Examples
Page 1 of 2 | Next page