LinuxQuestions.org
Review your favorite Linux distribution.
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 12-01-2011, 10:34 AM   #1
ranjitcool
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Rep: Reputation: 0
What is this line doing?


Hey Guys,

I know the command mkfs but what is this line doing stuff like - <fd.data> and am not 100% on what dev null has been for.


mkfs -t ext3 /dev/sdb1 < fd.data > /dev/null 2> /dev/null

Thanks
RJ
 
Old 12-01-2011, 10:42 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
< fd.data
Redirects in from a file called fd.data


> /dev/null 2 >/dev/null
Redirect standard output (a/k/a stdout which is file descriptor 1) to /dev/null AND standard error (a/k/a stderr which is file descriptor 2) to /dev/null. This could be simplified (and usually is) by writing:
> /dev/null 2>&1
The 2>&1 says to redirect stderr to stdout.

It is important when using this form that you define stdout before doing the 2>&1 because default is to the screen.
So if you did instead:
2>&1 >/dev/null
It would send stderr to the screen (because stdout was screen when you set stderr) but then send stdout to /dev/null because you defined it after the fact.

Last edited by MensaWater; 12-01-2011 at 10:44 AM.
 
1 members found this post helpful.
Old 12-01-2011, 10:54 AM   #3
ranjitcool
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for the reply.

I see the fd.data file has l p n w q all in a separate line. Now does the command pass all these switches in one shot or one after the other?

Also when i execute it I don't see any output while executing, only after its done (this is one line from a script that i picked).

So /dev/null is saying - if you get errors display on screen? I got confused with your explanation.

Thanks
RJ
 
Old 12-01-2011, 11:10 AM   #4
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
/dev/null is like a trashcan. Usually used for output. For instance if you do a find and you don't want to see errors you'd redirect errors to /dev/null.

So with your statement since it has both stdin and stderr going to /dev/null nothing will be shown.

As for the file -- it could be one of two things fs-options or a list of bad blocks.
 
Old 12-01-2011, 01:40 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
As the prior poster indicated /dev/null means "nowhere" essentially. This is called the "bit bucket". Redirecting to /dev/null is just a way to prevent output from showing up anywhere else - you're simply discarding it by sending it to the bit bucket.

I was saying that UNLESS you do a redirect the default for most stdout and stderr is the screen. Almost all redirects to /dev/null are simply to prevent output from appearing on the screen (or in log files when run in the background).

Redirects can be done TO or FROM files. In UNIX/Linux nearly everything is called a "file" including "device files" such as /dev/null, /dev/sdb, /dev/st0. You could redirect into a "regular file" called /tmp/mkfs.log if you wanted by modifying your original line as:

mkfs -t ext3 /dev/sdb1 < fd.data > /tmp/mkfs.log 2> /tmp/mkfs.log
--OR--
mkfs -t ext3 /dev/sdb1 < fd.data > /tmp/mkfs.log 2>&1

After you ran the command you could type "cat /tmp/mkfs.log" to see what kind of output it had.

I don't know off the top of my head what the entries in your fd.data file are doing. It's possible it isn't doing anything because it doesn't understand what was sent to it. Running to a log might give you better insight. (Alternatively you could simple NOT do the redirects to stdout and stderr and it would go to the screen.)

However, since you don't know what /dev/null is it appears you really need to drop back and NOT muck with this. mkfs will overwrite your /dev/sdb1 partition if you have anything on it already.

You might want to do a search for "Linux tutorial" - there are many places on line to read for example this one:
http://www.ee.surrey.ac.uk/Teaching/Unix/

It is OK to ask questions but you really ought to work your way up from basics to more advanced topics and ask questions as you go along. You don't need to know everything all at once but if you don't know about /dev/null or redirects you DO need to go and learn about the basics before you do some damage to your system.
 
  


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
[SOLVED] Insert line using sed or awk at line using line number as variable sunilsagar Programming 11 02-03-2012 10:48 AM
[SOLVED] Copy and replacing specific line from file1 to file2 line by line vjramana Programming 10 03-28-2011 07:49 AM
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM

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

All times are GMT -5. The time now is 12:46 AM.

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