School of Computing. Dublin City University. Home Blog Teaching Research Contact
Online coding site:
coders JavaScript worlds |
|
|
Explore commands and options by typing
"man (command)"
e.g. "man ps"
clear Clear screen
ls List files ls -a Show "hidden" files (begin with ".") ls -l Detailed ls -alR Recursive cat (file) Type file out in command-line window more (file) Type file, pause for each screenful enter for new line, space for next page, q to quit
cp Copy files mv Move / Rename files rm Remove files mkdir Make directory rmdir Remove directorySee tutorials on manipulating files with cp, mv, rm, etc.
(prog) & Launch a process detached from command-line (e.g. windowed) (prog) Command-line frozen until prog exits. eog file.jpg & Launch image viewer Eye of GNOME on file
firefox & Launch Web browser from command-line firefox "URL" & google-chrome & konqueror "URL" &
sort Sort alphabetically (pipe some stream into sort) sort -n Sort numerically sort -r Reverse sort sort by 5th column: sort -k 5 old syntax to sort 5th column: sort +4
grep Search for a string in a file or files grep (string) (file) grep (string) *html grep -i (string) (file) Ignore case grep -v (string) (file) Return lines that do NOT match
find Find files by type/date/name, in this dir or below find -type d Find all dirs find -mtime -1 Find files modified today
du Space used by me du | sort -n # why -n? default is k listing in M du -BM listing in G du -BG top-level only --max-depth=1
lp (file) Print lpr (file) Print (on some systems) lp -Pl128 (file) Print on printer l128 (L128) lpq See print queue lprm Remove job from queue
cal Calendar cal 8 1752 Calendar for Aug 1752 cal 9 1752 Calendar for Sept 1752 cal 10 1752 Calendar for Oct 1752
which (prog) what runs if "prog" is typed may return nothing if prog is an alias which ls type (prog) returns path of prog or else shows what prog is alias for type h type history whereis (prog) Where the binary, source, manual pages are for this prog whereis perl
df -h Show space on all disks df -k exact kilobytes w Who is logged in (see this when you ssh student.computing.dcu.ie) (command) ; (command) Multiple commands on same line
wget -q -O - URL Download URL, quiet, output to command-line wget -q -O - URL > file.htm Output to file wget -q -O file.htm URL Output to file wget -q -O - http://site/file.jpg > file.jpg Output JPEG to file (output JPEG to command-line won't work) wget -q -O file.jpg http://site/file.jpg Output JPEG to file see more on wget
index.htmlWhat file that refers to depends on what directory you are in now.
../index.htmlis also relative path. It looks for index.html in the parent of the current directory.
Directory before | Command | Directory after |
/users/gdf | cd users/ec2 | /users/gdf/users/ec2 |
/users/gdf | cd ../ec2 | /users/ec2 |
/users/gdf | cd ec2 | /users/gdf/ec2 |
/dir/dir/dir/public_html/index.htmlGives the full "path" from the root down to the file.
Directory before | Command | Directory after |
/users/gdf | cd /users/ec2 | /users/ec2 |
Case matters in filenames in UNIX (this is why case often matters on Web).
Question: Is case sensitivity a good thing? Or is it a flaw in UNIX?Advantages of case sensitivity:
Solutions to "404 Not Found" because of case:
Long file names and multiple periods OK.
e.g.
product.4652.suppliers.us.html
#define NAME_MAX 255 /* # chars in a file name */ #define PATH_MAX 4096 /* # chars in a path name including nul */
Avoid these chars in filenames, because they have meaning to the Unix command-line and utilities:
space (separate arguments) # comment < redirection > redirection ` result of a program | pipe & detach process ; separate multiple commands on the same line * wildcard ? wildcard ^ start of line $ end of line / variable value [ pattern matching ] pattern matching \ "quoted" character / should be in pathname, not filename ' string delimiter " string delimiter ! shell history |
0-9 a-z A-Z Use these inside filename only, not at start or end: . - _ |
$ find . | grep ' '