Tuesday, 27 February 2007

10 Linux commands for the Linux newbie

So you took the leap and installed a Distro of Linux and had a feel around of the layout and have noticed a app called ‘Terminal’.

No matter what you use Linux for, at some point you are going to have to use Terminal. So here are the most common commands any Linux newbie should know to be effective.

1) ls

This basic command is the command you will use the most to brows into the filesystem. Use it to list the contents of a directory.

A) To view details such as the file permissions, user and group owner, last time file was modified pass the l option as such
ls -l

B) You can search for filenames by using wildcards (*). To list files that start with the letter f, use

ls -l f*

2) find

This command will become your best friend when using terminal. The find command will search where you want it to search and find directories or files that match conditions such as name, date last accessed, file size and more. It has a number of abilities, all of which are listed in the ‘man’ page.

To search for files starting with the letter B recursively starting from the / root directory use the following

find / -name b*

3) man

What is the man command? man stands for manual so man page stands for manual page and most Linux commands have manual pages to describe how the command is utilized. This is a great feature if your not sure what a command does. To use the man command with another command you just need to type

man (command)

4) vi

As I mentioned in my previous post Vi is my favourite Editor when it comes to editing and coding in Linux.

Vi has 2 modes, command mode and insert mode.

1. command mode

Here are some of the basic command to get you through the editor:



h = move the cursor 1 character left

j = move the cursor 1 character down

k = move the cursor 1 character up

l = move the cursor 1 character right

i = enter insert mode before cursor

I = enter insert mode at begging of line

a = enter insert mode after the cursor

A = enter insert mode at the end of current line

o = create a new line below current line and enter insert mode

O = create a new line above current line and enter insert mode

/string = searches for the first instance of string

n = next occurrence

$ = move the cursor to end of line

:x = move cursor to line x

u = undo

r = replace single character

R = like insert mode but replaces characters until [Esc] is hit

x = delete single character

dw = delete word

dd = delete line

D = delete rest of line after cursor

yy = copy line

p = paste

g = returns line number

:w = save file

:q! = quit without saving

:wq or ZZ = save and quit



2. Insert/replace mode mode

You can type just as you would in any editor.

To quit and return to command mode press [Esc]

5) cat

You want to view the contents of file? The ‘cat’ command will show you the details.

Here’s how you can use the command

cat linuxhowto.txt

6) more

Most cases when it comes to files which you have accessed using the cat command. Its unlikely that it will fit on one screen. This is where the more command becomes useful. You can use this command to force the cat command to display the information one screenfull at a time.

cat linuxhowto.txt | more

7) grep

The grep command is what you would use to search for certain words or phrases in a file. For example you wanted to search for the word “sudo” within a file. We would use the following command.

grep “sudo” linuxhowto.txt

If there are matches, the lines containing “sudo” will be displayed.

8) chmod

You have a script that you need to run,By utilizing the “ls -la” command you can see if the script has execute permissions. If it doesn’t you may give it execute permission by running

chmod +x scriptfile

And of course, you can run the scriptfile if it is a script by running it with a ./ preceding the filename on the shell command line like so
./scriptfile

9) ps

What processes are running under your account. The ps command will show you.

10) cp, mv, rm

How do you copy, move or remove a file? There are actually three different commands for each of these functions.

A) copy
cp oldfilename.txt newfilename.txt


B) move
mv oldfilename.txt newfilename.txt


C) delete
rm oldfilename.txt

No comments: