Francais | Espanol | Deutsche | Italiano | 中文 | 한국어 | 日本語 |

This blog is owned by
Amey Palyekar
software engineer by profession

Subscribe

Add to Technorati Favorites
~My Links~


Google
Mozilla
MSN
Gmail
YAHOO!
 


~Archives~


October 2006
April 2007

~Credits~


Computer Blogs -  Blog Catalog Blog Directory

 

Linux Commands References I

Apr 7, 2007
Basic File/Text Manipulation

cat
To ‘concatenate’ files and then print on the standard output. i.e. cat file1 file2 will print out the contents of ‘file1’ followed by ‘file2’

ls
To list the contents of the directory specified by ‘path’. If no path is specified, then list the contents of the current directory.

less
To open ‘file’ in a primitive text reader that will allow you to scroll through a file using the arrow keys.

pwd
display current working directory

ps
To show current running processes on the system.
options: -l process status in second column
-f show owner
-e old and current process
ps -ef grep Amey - process with owner as Amey
ps aux grep process We print the entire process list, and we pipe standard output, using the ‘’ to the standard input of ‘grep’.

bc
Simple command line calculator.

bzip2
File compression/uncompression using the bzip2 standard.

chmod/chown
Change file permission modes/file permission ownership.

cp
Copy a file

mv
Move a file

grep
Text matching using regular expressions (regexes).

echo
Print a stream to standard output.

pico/nano
Simple text editor

vi/vim
More advanced text editor

Redirection
We can redirect the standard output and standard error streams from a file.
Example:echo “test” will print “test” to standard output, which in this case is the screen. echo “test” > outputfile will redirect that standard output into a file called “outputfile” which will be created if it doesn’t currently exist. Just as > redirects standard output, 2> redirects the standard error stream. Example:./program > output_file 2> error_file

Forking into the background

ctrl Z - To suspend current process in foreground.

bg - to send current process suspended to background

jobs - to get the list of jobs running in background
+ sign at start of job in list denotes default job running in background.
- sign at start of job in list denotes next default job after current default job finishes in background.

fg [pid] / [pname]
brings background job [jobno] to foreground.
fg without jobno will bring default job to foreground.

We can fork any process into the background, using ‘&’. Example: ./process &And this will ‘daemonize’ the process.

We can then find this process’s PID (Process ID): ps aux will show all processes, and we can then kill -9 to terminate this process; -9 will kill process urgently.
we can also use kill comman in following way
Kill [pid] - pid is process identifier uniquely aasigned by unix kernel; you can get pid from ps comand, here we can also give kill -9 [pid]
or kill [pname] - here pname is process name; but beware this may also kill some other users process so kill [pid] is often used.
for background job - kill %[jobno]

nohup
continue command even after session have logged out
e.g: nohup lp speech &
This command will put the lp command in background even after logged out, so it keeps running.

wait [pid]
makes current process wait until the pid process has finished.

at 1:00
to schedule the job at specified time;one can use 24 hour clock or 1pm, 1:00pm, 7pm
more e.g's: at 1:00 oct 23
at now +1 year
now, noon, midnight, today, tommorrow.
at 1:00 > lp speech - specify the lp command to run at said time.
ctrl d - to exit out of at command
at -l = to see all scheduled jobs with at command.
at -r [jobno] - to cancel job with jobno.

crontab
to schedule job every time after same period.
this is done in directory /var/spool/cron/crontab in this directory there are files for different user, insert your crontab command in file with your username.
crontab [-e] [-l] [-r]
-e : edit
-l : listed
-r : removed

Lists
We can separate commands on the command line with either a ‘;’ or a ‘&&’. Using a semicolon means that each command will be executed in order regardless of the result of the last. Using a double ampersand means that the next command will only be executed if the last one succeeded.

Help Commands

Man
you can use man command any time to get complete knowledge of commands.
e.g.: man ps - will give complete help on PS command with various switches used with ps.

The ability to switch between foreground and background process is called job control.

Labels:

1 Comments:

At 3:37 AM , Anonymous Anonymous said...

THANKS
This has really helped looking for next article on this

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home