LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   some questions (https://www.linuxquestions.org/questions/linux-newbie-8/some-questions-406566/)

itz2000 01-22-2006 12:07 PM

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!

Boby 01-22-2006 12:30 PM

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

aoshi 01-22-2006 01:47 PM

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.

pixellany 01-22-2006 02:44 PM

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.

itz2000 01-22-2006 05:05 PM

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?

jrdioko 01-22-2006 05:37 PM

Quote:

Originally Posted by itz2000
what is TLDP?

http://www.tldp.org/

chrism01 01-22-2006 07:34 PM

BTW, here's the link to Rute: http://rute.2038bug.com/index.html.gz

itz2000 01-23-2006 03:07 PM

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

jrdioko 01-23-2006 03:17 PM

Hmm... how about:

Code:

for i in `ls -t|head -3`; do totem $i; done

itz2000 01-24-2006 02:43 AM

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].

jrdioko 01-24-2006 10:27 AM

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.

itz2000 01-24-2006 04:37 PM

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...

jrdioko 01-24-2006 05:58 PM

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


All times are GMT -5. The time now is 04:49 AM.