*MAFIA* Forums

*MAFIA* Forums

  • April 26, 2024, 04:09:25 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome back the Arcade! Play over 100+ games to get the high score and compete against other forum members.

http://www.mafiaowns.com/index.php?action=arcade;sa=list;sortby=a2z;

Author Topic: Common Commands  (Read 1227 times)

Rahl

  • Forum Member
  • Reputation: 279
  • Offline Offline
  • Posts: 379
    • View Profile
Common Commands
« on: September 04, 2005, 09:37:08 PM »

For those of you who are just installing Linux or booting from a Live CD (e.g. Knoppix), here is a brief discussion on some of the shell commands you'll be using constantly.  Please note that Linux is case-sensitive.  ls and LS are NOT the same command.

For a more comprehensive discussion of any of the commands, consult the man pages.  Also, http://www.er.uqam.ca/nobel/r10735/unixcomm.html has some nice, general information.

ls - Short for list, this will display all the items in pwd (by default).  If you'd like to specify a directory to list the contents of, type in ls /my/directory/goes/here/
There are some flags that you can give this command as well to alter the output.  

ls -a will print ALL the files and directorys (including hidden files denoted by a . in the front of the name).
ls -l will print additional information regarding the file, directory, link, etc. that is listed.
The first column is the file type (d for directory, - for file, l for link) and permission masks.  rwx is read, write, and execute.  We see there are three sets of permission masks.  The first is for the owner of the file, then for the group the file belongs to, and finally for any other user.  Column two is the number of i-nodes which refers to how many indexes there are to the file.  When this is zero, that file is gone with no hope of recovery.  Columns three and four are the user and group that created the file.  Then we have the size in bytes, date and time created (or modified) and finally the name.
Code: [Select]
drwxr-xr-x   3 keelerm users  224 2005-07-01 19:38 bin ls -R will recurse the directory provided and display all the items, relative to their subdirectories .

cd - change directory.  Fairly self-explanatory.

rm - Remove.  This will destroy any file it's pointed at.  This will not remove directories natively.  That requires the rmdir command (dir must be empty).  If you want to remove a non-empty directory with rm, type rm -dR.  The d denotes it's a directory and like ls, the R is for recursive descent.
I suggest you use rm with the -i flag.  This will prompt an "are you sure" safety check so you don't shoot yourself in the foot.

cp - copy a file.  To copy a directory, Note that you must use the dR flags.  When using the cp command, it's copy /source/path /destination/path  Same for the mv command which we'll discuss next.  Again, I suggest you use the cp -i command to do checks.

mv - move this file or directory.  You can also use this command to rename files.  Let's say we want to rename the file example in the /home/ dir to myExample.  We would issue mv /home/example /home/myExample.

less - displays the contents of a file.  Use the arrow keys to move up and down.  q to exit.

grep - This is a pattern matcher.  It's easier to explain through an example, so let's say we were in a directory with 4,000 files named RahlOwnsAll000 0-RahlOwnsAll3999.  If you were just curious about the information regarding RahlOwnsAll002 1, instead of ls -la | less and scrolling through all the pages, you could issue ls -la | grep 0021.  This would match the line with the string 0021 and display only that.
The flag -v prints just those lines that don't match your expression (more handy than you'd think).
-e tells grep you're going to use regular expressions (tutorial to come later).
-E tells grep to use the extended regular expressions.  This is the same as just issuing the egrep command.  Note:  Not all distros have egrep.

** most Linux commands are filters, meaning they read from standard input (keyboard) and read to standard output and standard error (terminal screen).  You can "pipe" the output from one command into another command using | like I did with the grep command.  There is also redirection (<, >, >&) which lets you read or write from files, but we'll worry about it later.

whereis - find an executable program.  Example:  
whereis firefox
firefox:  /home/keelerm/Programs/firefox

locate - find anything that matches the parameter you pass it.  Example locate firefox
Anything that has firefox in the name or path will be displayed.

You must run updatedb before you can use locate.  Locate searches a database of all the files on your computer so it's fast.  updatedb takes a while to do, but it's worth it.  This must be done periodically.  If someone is interested, contact me or Toby and we'll show you how to make it run updatedb regularly through the crontab.

ps - Display the processes running.  This is a quick way to see what's running, you won't use this as often, but I thought I would throw it in.  ps ax is a more comprehensive listing, but I won't go into the criteria.  top is a similar command.  It's like viewing the processes tab from Ctrl-Alt-Del on Windows.

Remember, this is no where near a comprehensive or indepth look into the commands.  Most commands contain at least 5 flags (some with like 25+) and there are hundreds upon hundreds of commands.  However, this should provide a sufficient level of functionality for the Linux beginner.  Hope you find it handy.
Logged

Swifty

  • Forum Member
  • Reputation: 295
  • Offline Offline
  • Posts: 684
    • View Profile
Common Commands
« Reply #1 on: September 05, 2005, 12:04:13 PM »

Wow this sure puts things into context *Scratches Head*
Logged
 

Page created in 0.034 seconds with 30 queries.