when someone tried linux for the first time he stumbles onto one simple problem, he/she does not know how to use linux command in konsole. Because he is not familiar with it. In this article I will explain to you the basic usage of linux command in konsole
a. Redirecting IO
linux has the ability to redirect its input/output. Linux process begin its life with three open file descriptors, standard in, standard out and standard error. Standard in is the source of input for the process; standard out is the destination of the process output; and standard error is the destination for error messages.
redirecting I/O is accomplished on the linux shell command line by the “<” and “>” characters. here is a sample
consider the ls program that will print the list of files in the current directory
jack@jack-opensuse:~/kuliah> ls
01 Pendahuluan 12022008.pdf
02 Representasi Informasi 22022008.pdf
abubakar.pdf
DaNAMiCS manual.ps.gz
jim_mcquillan_07.pdf
Lecture06-06-Petri Net.pdf
ltspguide.pdf
ltsp.ppt
LTSP_T-1225.pdf
ltspuser.pdf
RekPro-20062-FAZ-04a-Overview of Distributed System.pdf
RekPro-20062-FAZ-04b-Basic Design Concept.pdf
RekPro-20062-FAZ-05a-Requirement and Service Specification.pdf
RekPro-20062-FAZ-05b-Protocol Architecture.pdf
suse13.pdf
we can redirect its output to another location, a file with the “>” character
jack@jack-opensuse:~/kuliah> ls > my.files
if you open my.files in your current directory the result from ls is redirected to that file.
b. sort
we can use sort to print the text back out, sorted by the first character of each line
jack@jack-opensuse:~> sort
Bandung is the best city
I like living here
sometimes I miss my hometown in batam
hope can go home again
^D
Bandung is the best city
hope can go home again
I like living here
sometimes I miss my hometown in batam
after you finish typing the text then press ctrl+D for sorting the text back out, now can you redirect its output to another file?
c. Pipes
the output of one command can also be sent directly to the input of another command. this process is called pipe.
jack@jack-opensuse:~> ls | wc > wc.file
this command firstly run ls which will list the file in the current directory, then pipe its output to the input of the wc program which will count how many word, line and characters are use. The output of the wc command is redirected to the wc.file
d. ls
the ls command is so basic, showing the names of files in a directory
ls : list the file in a directory
ls -l : the long form, showing permissions, ownership, and size
ls -ld : to see the directory permissions
ls -lrt : show the most recently modified files last, so you can see what you’ve just changed
e. filenames
filenames are case sensitive, upper and lowercase names are different. myfile.txt and Myfile.txt could be in the same directory but they are different.
avoid using spaces in filenames, as the shell uses whitespace to differentiate between arguments on a command line. You can put a blank in a name, but you have to use qoutes to refer it to the shell
f. permissions
in linux there are 3 user, the owner, the groups, and the others. To change the permissions you can use the syntax below
chmod a+r file : gives everyone read permissions
chmod go-w file : takes away write permissions from group, others
chmod u+x file : sets up a shell script so you can execute it like a command
chmod 600 file : sets permissions to read and write for the owner but no permissions for anyone else
g. file copying
the mv command lets you move a file from one directory to another. when you move it, you can give it a new name. if you move the file without putting it in another directory then you just rename that file.
jack@jack-opensuse:~> mv wc.file wc.newfile
jack@jack-opensuse:~> mv wc.newfile /home/jack/kuliah
jack@jack-opensuse:~/kuliah> mv my.files mine.files ..
jack@jack-opensuse:~> mv /home/jack/kuliah/*.pdf .
the first example moves wc.file to new name, wc.newfile while leaving the file in the same directory
the second example moves the file name wc.newfile from current directory to the /kuliah directory
the next example just moves the two file up one level, to the parent directory. The “..” is a feature of every linux directory. Whenever you create a directory, it gets created with two links already built-in: “..” point to its parent and “.” points to the directory itself. the last example lets you move all files in a directory to up one level.
the cp command is much like the mv command, but the original file is left right where it is. In other words it copies file instead of moving them.
jack@jack-opensuse:~> cp passwd.1 /home/jack/kuliah
will make a copy of passwd.1 to /kuliah
jack@jack-opensuse:~> cp *.pdf /home/jack/kuliah
will put the copies of all the pdf in the current directory to the /kuliah directory
the ln command will make a link to your file, a link is used to make another file with the same content so that when we edit one of the file the other file will be edited too.
jack@jack-opensuse:~/kuliah> ln ltsp.ppt /home/jack
the file command tries to tell you what kind of file it found
jack@jack-opensuse:~/kuliah> file *
03_Editorial_01.pdf: PDF document, version 1.3
04_Indeks_01.pdf: PDF document, version 1.3
06-09_Aktual & Profil_01.pdf: PDF document, version 1.3
10-14_Opini_01.pdf: PDF document, version 1.6
DaNAMiCS manual.ps.gz: gzip compressed data, was “manual.ps”, from Unix, last modified: Thu Oct 8 23:05:51 1998
ltsp.ppt: Microsoft Office Document
passwd.1: empty
the file looks at the first several hundred bytes of the file and does a statistical analysis of the types of charactes that it finds there, along with other special information it uses about the format of certain files
if you only need to check the top few lines of a file, use head. You can choose how many lines from the front of the file to see with a simple parameter. The command head -7 will write out the first seven lines, then exit
if you interested is the last few lines of a file, use tail. the syntax are the same as head. Also tail can be used to watch log file.
jack-opensuse:/home/jack # tail -f /var/log/messages
Apr 8 18:20:31 jack-opensuse smartd[3566]: Device: /dev/sda, SMART Usage Attribute: 190 Temperature_Celsius changed from 52 to 50
Apr 8 18:20:31 jack-opensuse smartd[3566]: Device: /dev/sda, SMART Usage Attribute: 194 Temperature_Celsius changed from 48 to 50
Apr 8 18:20:31 jack-opensuse smartd[3566]: Device: /dev/sda, SMART Usage Attribute: 195 Hardware_ECC_Recovered changed from 65 to 64
Apr 8 18:49:59 jack-opensuse syslog-ng[2560]: STATS: dropped 0
Apr 8 18:54:10 jack-opensuse hald: unmounted /dev/sdb1 from ‘/media/JACOBIAN’ on behalf of uid 1000
Apr 8 18:54:11 jack-opensuse kernel: usb 1-8: USB disconnect, address 7
Apr 8 19:49:59 jack-opensuse syslog-ng[2560]: STATS: dropped 0
Apr 8 19:50:31 jack-opensuse smartd[3566]: Device: /dev/sda, SMART Usage Attribute: 190 Temperature_Celsius changed from 50 to 51
Apr 8 19:50:31 jack-opensuse smartd[3566]: Device: /dev/sda, SMART Usage Attribute: 194 Temperature_Celsius changed from 50 to 49
Apr 8 19:56:08 jack-opensuse su: (to root) jack on /dev/pts/0
press ctrl+c to stop logging file.
h. the grep command
grep acronym for “Generalized regular expression processor” is a tool for searching through the contents of a file. it searches not just for fixed sequence of characters, but can also handle regular expression.
jack-opensuse:/home/jack/kuliah # grep yakob *
jack:my name is yakob
I have created a file name jack and write it with a sentence : my name is yakob. grep can be used to find specific information in the file that we want to search.
options for grep
-i : ignore upper/lowercase differences in its matching
-l : only list the filenames, not the actual line that matched
-n : show the line number where the match was found
-v : reverses the meaning of the search – shows every line that does not match the pattern.
i. the find command
this command looks for a file whose name contains jack. It starts looking in the current directory and descends into all subdirectories in its search
jack-opensuse:/home/jack/kuliah # find . -name ‘*jack*’ -print
./jack
./jack~
well that’s it for now. I hope this tutorial would benefits you. If you have any question feel free to ask me anytime you want.
Wedew..your the all of your posting in english. Is it your own posting????
It’s a good writing.
ooo.. i remember a lesson at IT Telkom… it’s also talking about linux.
yupz, good posting… sharing your knowledge… ok 🙂
thats for sure, dude
can nyone help me to know somthng abt linux…i hv a interview after 2days…plsssssss…………