Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'd like to know how to use those stuff so can I have quick example + tell me what they exactly do?
It will take 1 minute!
tail
head
cat
grep
psudo
I would also like to know how can I close process to not run in startup... (in xp it's run-->Msconfig) I think it has to do with initrd in linux right? I'd like to know what shall I do (via terminal only)
also... a link to a guide how to compile a kernel would be great in shortly like
I'd like to know how to use those stuff so can I have quick example + tell me what they exactly do?
It will take 1 minute!
tail
head
cat
grep
psudo
Read the manual entries:
Code:
man tail
man head
man cat
....
Quote:
I would also like to know how can I close process to not run in startup... (in xp it's run-->Msconfig) I think it has to do with initrd in linux right? I'd like to know what shall I do (via terminal only)
Examples:
tail -5 myFile - prints last 5 lines of myFile
tail -c 5 myFile - last 5 characters
head - read first N lines/characters, use as tail
cat - print the whole file
grep - find lines that match a pattern in the file
The most simple pattern is normal word (letters and numbers)
Let's assume you have a file called "testfile", containing this poem by Ogden Nash:
Tell me, O Octopus, I begs,
Is those things arms, or is they legs?
I marvel at thee, Octopus;
If I were thou, I'd call me us.
Then if you type:
grep Octopus testfile
the result will be two lines:
Tell me, O Octopus, I begs,
I marvel at thee, Octopus;
(these are all lines that contain the word "Octopus"
You may create more complex patterns with the dot (.) meaning any character and the asterisk(*) meaning "repeat any times". If you write .* this means "any character repeated any times" which is simply "anything". If you use * you must write the pattern in quotes ("").
Note that meaning of * is different than when using with filenames like "ls *.txt"
For example:
grep "Is.*legs" testfile
will give this line:
Is those things arms, or is they legs?
because this line contains "Is", then "anything" (.*) and then "legs"
For more info read the manual (man grep) as written in previous mail
----- These commands become much more useful if you use so-called pipes
Pipe is the vertical line | (on my keyboard I must press shift and backslash to get it, but it may be different on yours). The usage of pipe is
command1 | command2
The output produced by command1 is passed as input to command2
For example:
ps -ef | grep sh
Command "ps -ef" prints all running processes
Command "grep sh" finds all lines containing the text "sh"
If you use the construction "ps -ef | grep sh", the list of processes will not be printed, but passed to grep. Grep will work on the list of processes instead on a file. Thus, it will print all processes whose name contains "sh". These will be probably bash or tcsh or csh or something similar. These are the shells that is programs which process the commands that you are typing.
Another example, this time with tail:
ls -1 -t | tail -3
Command "ls -1 -t" prints all files in the current directory, sorting by time (starting with newest files and ending with oldest). It prints one file in a line (thanks to the "-1" option)
Command "tail -3" prints three last lines
This way "ls -1 -t | tail -3" prints three oldest files (or directories)
Other useful trick is the backquote (``). It executes a command and uses the result as other command's arguments. See the example with rm command (this command removes a file):
rm `ls -1 -t | tail -3`
As explained above, "ls -1 -t | tail -3" prints three oldest files. The command above will remove the 3 oldest files. Don't try using it in a directory which contains important files!
Note: this will not work if a directory will be found instead of a file. To make it work on directiories too, all you need to do is add "-r" option to "rm":
rm -r `ls -1 -t | tail -3`
This will remove 3 oldest files or subdirectories in the current directory.
Some shells (for example bash) also allow to use $(command) instead of the backquote `command`:
rm -r $(ls -1 -t | tail -3)
This will do the same as the previous form if you are using bash.
One more useful thing - redirection
If you want the result of a command to be saved to a file, instead of displayed it on the terminal, just type
command > file
For example:
ls -l > my_things
This will create the file called "my things" and this file will contain list of files in the current directory.
ps -ef > my_processes
And this creates a file called "my_processes", containing list of all running processes
If the file "my processes" already exists, it will be overwritten. You can use >> instead of > if you want to add new contents to the file instead of overwriting it.
Did you enter the backticks correctly? The ` marks around "ls -t|head -3" are not single quotes and not optional--they're the key usually above Tab and to the left of the number 1.
What's happening here is that you have to call totem with each entry in "ls -t|head -3", but you can't pipe it directly into totem. Then it would be the same as typing, for example, "totem /home/zuki/mp3/foo /home/zuki/mp3/bar /home/zuki/mp3/baz", which isn't the right way to invoke totem. Instead, you need to split it up into three separate calls. The for loop says "for each file that you get from running this command (the one between backticks), call totem with that filename."
But maybe there's an easier way to do this. Are you just looking for a normal playlist? I don't know anything about totem, but any decent audio player should be able to make and read .m3u playlists for mp3 files. Restarting the audio program each time with a new song doesn't seem like the right way to go about doing that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.