Unix/Linux 101 – Understanding Commands

Understanding Unix/Linux Commands
A command is when you tell the computer to do something you want it to do. You can use commands to work with files – like copy, move or print. You can use commands for executing programs and you can use them to communicate with other users. There are many many commands, all written to make your life a little easier. Typically, commands are stored in the “/bin” directory. IRIX holds another directory “/usr/sbin” where it holds more commands targeted mostly towards image manipulation and other graphic purposes. In order to execute a command you have to have two criterions meet:
1.The command has to be executable in its permissions (we’ll talk about permissions later)
2.The directory where the command is stored has to be included in the “Path” environment.
When you type “echo $path” in a shell, you will see a set of directories. The content of these directories is loaded into a part of the memory called a “hash table”. When you type a command the system looks into the hash table and if that command doesn’t exist there it will report the command is not found. In the article “Intermediate Unix and Unix scripting for animators” I’ll explain how you can add more directories to the “path” environment, as well as using other viariables.
* Note – often, you can still execute a command in the current directory without that directory being in the path. The file, however, will still need to be executable.
Commands in Unix/Linux can be run the way they are, but often times their syntax requires more input from you than simply just typing the command name. You have seen the “pwd” and “cd” commands up till now – which didn’t require extra input from you (although you can), but now we’ll look into other basic commands and how they work.
Almost all commands use “flags”. Some call them “options”, some call them “switches”. Flags are represented by the minus sign “-” followed by the flag itself with no spaces. Typing “date” in the command line will show you the current date and time. If you want to see the time in Greenwich time, you would use the “u” flag:
# date -u
To learn about all the flags of commands always use the “man” command. The “man” command shows you a manual of almost all commands. It first shows the syntax of the command, then a description of the command, all the flags, examples, notes, and finally related commands. To use the “man” command for “date” type:
# man date
Space-bar advances the pages, “q” exits.
Here are some common commands and some common flags with a very brief description. Use the “man” command to get more info on how to use them:
“ls” – list files (similar to DOS’s “dir”)
“ls -la” – show listing in long (“l”) format, show all (“a”) files. Long format shows permissions, ownership, size, and time and date of creation. All – shows hidden files as well (files beginning with “.” are hidden).
“ls -r” – list also subdirectories
“mkdir” – make directory (similar to DOS’s “md”)
“mkdir temp” - makes a directory called temp
“rmdir” – remove directory (similar to DOS’s “deltree”)
“rmdir temp” - remove a directory called temp.
“rm” – remove file (similar to DOS’s “del” command)
“rm -rf” – remove recursively (including directories) and forces read-only files too
“rm -ri temp” – remove the temp directory and all contents, prompting for confirmation
“mv” - move or rename
“mv oldname newname” – renames oldname to newname
“mv newname ..” – moves the file “newname” to the parent directory
“cp” – copy
“cp -r images temp” – copy the whole directory “images” to the “temp” directory
“ln” – create a hard link of a file (a copy that updates the original)
“ln -s” create a symbolic link of a file (similar to Windows’ “shortcut”)
“ps” – process show – show executed commands
“ps -ef” – show All processes (e) in full listing (f)
“kill pid” – kills a process. PID is the process ID number.
“kill -9 pid” – kill a process immediately without waiting for a return signal.
“df -k” – disk free – shows free disk space in Kilobytes
“du -sk” – disk usage – show summarized (s) space in kilobytes (k)
“cat filename” - display the contents of a filename (catalogue)
“more filename” – display the contents of a filename one page at a time
“who”, “w” – show logged on users
“whereis” - find the path of a command
“pwd” – show your Present Working Directory
“passwd” – change your password
“find” – find a file or text.
“find ~ -name movie.mov” – search only in home-space a file named movie.mov
“grep” – find a pattern in files
“file” – show the type of file
“hinv” – shows hardware configuration
“whoami” – shows you your username
Note – when you delete a file in DOS or Windows you’re actually just deleting the file’s first character from the File Allocation Table. That file is retrievable as long as no other file has taken its place. In other words, when you delete a file it’s still there, giving you a chance to undelete it – but it still shows the system its place is vacant for other files to occupy. If the system does store another file in its place, the older file is no longer retrievable (in whole at least).
In Unix there is no such thing as undeleting. When you delete a file the system places zeros “0″ all over it clearing its place entirely. Unless you backed up the file somewhere else, there is no way of retrieving that file after deletion. Therefore, be extra careful when removing files and directories. To be safe, use the “i” flag in the “rm” command to prompt you whether you definitely want to remove the file specified.
Tags: Dani Rosen, linux, tutorial, unix





Sat, Jan 5, 2008
Unix/Linux