Monday, November 16, 2009

Linux Commands - Programming

* cksum - calculate the check sum of a file, used to verify if two files are identical. Example: "cksum file1.txt" returns a number as the finger print of the file1.txt.

* echo - "echo $PATH" displays the value of environment variable PATH.
* env - displays all environment variable.
* export - write a variable to harddis. Example: "export MYVAR=$HOME" assigns the value of HOME to MYVAR, then set MYVAR as an environment variable.
* declare - declare variables and give them attributes. Example: "declare MYVAR=$HOME" assigns the value of HOME TO MYVAR, but does NOT set MYVAR as environment variable.
* read - read input from standard input, assign it to a variable. Example: "read newvar", input a value for newval, then "echo $newvar".
* sleep - delay for a some time. Example: "sleep 2" delay 2 seconds.

* alias - allow users to create abbreviations for complex commands. Example: "alias" displays all the existing aliases. Example: "alias mycmd="pwd" "
* unalias - delete an alias. Example: "unalias mycmd".
* nohup - run a command immune to hungups. Example: "nohup ls" run the command ls, write the output to file nohup.out.
* tee - "ls | tee file.out" this command display the output of command ls at standard output, while write them to the file.out. "ls >> file.out" won't display the output at standard output.
* sed - search and replace patterns in a file. Example: sed 's/my/your/g' afile.txt --this command substitute all "my" to "your" in the afile.txt.
* cut - divide a file into several parts. Example: "cut -d, -f1,3 sample.txt" divide lines by delimiter :, then output the first and third columns.
* sort - sort text files.
* paste - merge lines of files.
* split - split a file into many parts. Example: "split -b 1024 example.data new" split example.data into file newaa, newab, newac... each file have 1024 byte.
* vi - text editor.

* top - display the system resources statistics, and the updating processes.
* ps - display the running processes. "ps -A" displays all the running processes.
* kill - stop a process from running. "kill -9 3214" stops the process with id 3214 immediately.

* watch - execute a program periodically. Example: "watch -n 5 free" execute command free every 5 second.
* crontab - schedule tasks running periodically. Example: "crontab -l" list all the scheduled tasks for the current user. "crontab -e" edit the scheduler. For example, a task record could be "2 12 * * 5 /sbin/ping -c 1 www.google.com >> /dev/null", which means, ping google every 2 minutes at 12 o'clock on every friday. "crontab -d" delete all the scheduled tasks for the current user.

* chkconfig - control services. "chkconfig" displays the states of all the system services. "chkconfig sshd on" turn on the ssh service.

No comments:

Post a Comment

Why I stopped publishing blog posts as information provider

Now the AI can generate content. Does that mean the web publishing industry reaches the end? ChatGPT said: ChatGPT Not at all. While AI can ...