Friday, December 4, 2009

Linux Basic Cmd

Pertama-tama Linux cmd are sentsitive case misalnya 'A' xsama dgn 'a'.
Basic cmd you must know

- pwd - Prints out on the screen the working directory (eg /etc/ssh)
- cd - changes directory (eg cd .. - goes up one dir; cd etc - enters /etc dir)
- ls - lists the content of the directory
- mkdir - creates a new directory (mkdir dir_name)
- touch - creates a new file (touch file_name)
- rmdir - removes a directory (rmdir dir_name)
- cp - copies a file/directory (cp source_file destination_file)
- mv - moves a file/directory - also used for renaming a file or directory
(mv old_location new_location or mv old_name new_name)
- rm - removes files (rm file_name)

To search a file, you can use

- find (used for filenames)
- grep

To view a file, you can use

- more - will display a file page by page
- cat - displays all the file
- head - displays the first lines
- tail - displays the last lines (useful for example when you want to view the last information logged in a file by the system for example)

To edit a file you must use a built-in editor from the command-line. Generally, this is vi and it's used with the syntax vi .

To uncompress an archive (usually tar.gz) you must use the tar command with the syntax tar -xvzf .

To print a file, use lpr command. Note that you must have some daemons up and running to manage the printer. Usually this is cups (Common UNIX Printing System) that comes with all major distributions.
To remove a file from printer queue (you can list the queue with lpq command) you can use lprm .

To mount/unmount (add in your file system as accessible media) use:

- mount /mnt/floppy - to mount floppies
- umount /mnt/floppy - to unmount floppie
- mount /mnt/cdrom - to mount CD-ROMs
- mount /mnt/cdrom - to unmount CD-ROMs

They usually mount automatically, but you could end-up in the situation where you must do it manually.
To mount a partition:
First create a directory in /mnt (mkdir /mnt/my_new_drive) then use the mount command (mount /dev/source /mnt/my_new_drive) where /dev/source is the device (partition) you want to mount in your file system.

If you want to connect to a remote host, use the ssh command. The syntax is ssh .

System management:

- ps - shows the current processes running (useful: ps -A shows up all processes)
In the list obtained by using ps command you will see a PID number (Process identification).

This number is required to stop a service or application. Use kill to stop a task.

- top - works somehow like the Task manager in Windows. It shows up the system resources, the processes running, average load, etc. Useful is top
-d - sets up the refresh period. You can put any value from .1 (10 ms) to 100 (100 seconds) or even greater.

- uptime will display the system's uptime and the load average for that moment, 5 minutes and 15 minutes in the past.

Usually, the load average is calculated as the percent of system resources (processor, RAM, harddisk I/O, network load) used at that moment. 0.37 means that 37% was used. A greater value like 2.35 means that the system had to que some data because it should be 235% faster to compute all without problems. Anyhow, this can be different from distribution to distribution.

- free - will display information on system's memory

- ifconfig - view detailed information about your network interfaces; generally your ethernet network interface will be named eth0. You can also set up the network settings like IP address or so by using this command (see man ifconfig). If something goes wrong, you can also stop/start the interface by using ifconfig up/down

- passwd - enables you to change your password (passwd own_user or others if you are logged in as root)

- useradd - enables to add a new user (see man useradd)

Anywhere you are, you cand use the TAB key to autocomplete a filename or command. This will be usefull when getting used to the commands available. You can also hit up arrow and down arrow to scroll through the history of the commands you entered.
You can also use multiple command on one line. Let's say you want to create 3 directories at once. The syntax is mkdir dir1 ; mkdir dir2 ; mkdir dir3.
Another useful thing is the pipe command. You can get a command output through another. Eg: man mkdir | tail will display the last lines in the manual pages of the mkdir command.

If at anytime you are asked for the root account (the super-administrator of the system) you can login in temporary with it by using the su command. You should also include -l (su -l) parameter to switch the home folder and available commands too. Note that you will be prompted for a password too.

To exit the shell type exit or logout.

thanz n credit to cyber terrorist

No comments:

Post a Comment