LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-22-2006, 12:07 PM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
some questions


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

make
make modules
...


Thanks alot guys! I'm trying to summary stuff!
 
Old 01-22-2006, 12:30 PM   #2
Boby
Member
 
Registered: Feb 2004
Posts: 781

Rep: Reputation: Disabled
Hello!

Quote:
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)
Code:
system-config-services
http://wiki.linuxquestions.org/wiki/Runlevel

Quote:
also... a link to a guide how to compile a kernel would be great in shortly like
How to Compile a Kernel

Last edited by Boby; 01-22-2006 at 12:33 PM.
 
Old 01-22-2006, 01:47 PM   #3
aoshi
LQ Newbie
 
Registered: Jan 2006
Location: Krakow, Poland
Distribution: Gentoo, Aurox
Posts: 3

Rep: Reputation: 0
Lightbulb

tail - reads last N lines/characters of the file

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.

I hope that's enough for the beginning.
 
Old 01-22-2006, 02:44 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
You have gotten some good inputs here--the next step I would recommend is a book. You have obviously used Linux long enough that you will benefit.

FREE:
Bash Guide for Beginners by Machtelt Garrels---download from TLDP

$$, but worth it:
Linux in a nutshell from O'Reilly

Many others: Rute tutorial is one popular one--Google will find it.
 
Old 01-22-2006, 05:05 PM   #5
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Thanks aoshi! I've gotten smarter a bit cause of you!
Didn't know some of the things, thanks.!

Boby, thanks, but I already knew "man $entry" but it's used with not good examples IMO!

Thanks for the links though!.

aoshi, if you'd write a book, I will buy

@ Pixellany : what is TLDP?
 
Old 01-22-2006, 05:37 PM   #6
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Quote:
Originally Posted by itz2000
what is TLDP?
http://www.tldp.org/
 
Old 01-22-2006, 07:34 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
BTW, here's the link to Rute: http://rute.2038bug.com/index.html.gz
 
Old 01-23-2006, 03:07 PM   #8
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Thanks guys!

I'm trying to do a playlist of n last songs in the directory (all files are mp3), i use totem... but this one isn't working

Code:
ls -t |head -3| totem
suggestion?
Thanks
 
Old 01-23-2006, 03:17 PM   #9
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Hmm... how about:

Code:
for i in `ls -t|head -3`; do totem $i; done
 
Old 01-24-2006, 02:43 AM   #10
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
it looks bad... but i guess it's really good once you get used to it... right?

EDIT : it's not working! it says :
Code:
ERROR
Totem could not play 'file:///home/zuki/mp3/ls'.

There is no plugin to handle this movie.
I guess it sends to totem 'ls' or something, not the name of the files [there's no plugin problem offcourse].

Last edited by itz2000; 01-24-2006 at 02:47 AM.
 
Old 01-24-2006, 10:27 AM   #11
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
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.
 
Old 01-24-2006, 04:37 PM   #12
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
only succeded with
Code:
for i in `ls -t|head -3`; do totem $i*.mp3; done
dunno why...

it said without the *.mp3
Cannot open file Metallica for instance...
 
Old 01-24-2006, 05:58 PM   #13
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Don't know why it would work that way. Maybe someone with more knowledge of for loops can jump in.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
Solaris - Questions! Questions! Questions! qs_tahmeed Solaris / OpenSolaris 2 07-16-2005 05:27 AM
window manager questions and/or theme questions t3gah Linux - Software 2 02-27-2005 04:16 PM
two questions. wyatt Linux - Software 3 07-02-2004 06:56 PM
two questions Sophic Linux - Newbie 4 03-29-2004 08:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration