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.
In the bash shell, I am learning all about redirection and command usage. It is clear that the disjoint committee that designed all these commands had no regard for a standard syntax. One thing they all valued, however, was a desire to make each command and option as short, criptic and non-verbose as possible.
Thats why it puzzles me that I have not encountered a way yet to just have a command actually change the file it reads as stdin. Attempts to have the same file as stdout result in a blanking out of the stdin file. For example, don't do this if you want the file:
nl <somefile.txt >somefile.txt
or
nl <somefile.txt | tee >somefile.txt
It seems a violation of non-verboseness, the everything on one line rule, and a missed oportunity to create a new criptic one character operand for there to be no way to do this other than:
What you refer to as short, cryptic, and non-verbose is part of the essence of *ix systems. One day, you will learn to like it.
You don't "change files" at the command line---that is done in text editors--or hex editors. What you can do with files at the command line:
read
append
write
change ownership, access, and access time
to read or write (or append), you use any command that needs or generates data and you redirect the stdin and stdout to the file, eg:
ls > list creates a new file with the output of the ls command
cat file1 > file2 reads file1 and sends the output to file2
cat file1 >> file2 reads file1 and APPENDS the output to file2
cat file1 | grep word > file2 reads file1 and writes lines containing "word" to file2.
etc.....
touch file either creates file or updates its access time
rm file removes the file
In fact, may help, if you think about commands more like a filter that change the input in some way and output the modified data. In general, there is no files here, just a input flow and an output flow. Theses flows can come from files and goes to files but its just a special case !
An example:
cat | tr '[a-z]' '{A-Z]' | nl
Here, what you type is the input flow. But it can be ANY program's output, either the normal output or the error output, whatever. There is no file here. And the final result can be used inside a logical test inside a program, without files taking part in this game.
for file in `find $DIR -type f | sed -e 's#/# #g' | rev | cut -d" " -f 1 | rev`; do
echo "do something with file $file"
done
Here, I list all files below $DIR, and extract from the full path (/dir1/dir2/dir3/filename) just the filename part.
Again, there is no need to intermediate files. (Hey guys, I known /usr/bin/basename, this is just a example, ok?)
The point here is theses commands was designed to handle input flow and produce another flow.
Well, about the cryptic names I must agree without. But, I prefer cryptic names than aCommandWithVeryLongName, just like Pascal commands.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.