How to count the number of line in a file
Answer:
Use the wc command
wc -l text.txt
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How to count the number of line in a file
Answer:
Use the wc command
wc -l text.txt
Becareful when using the mtime option in find command
Answer:
A simple command like the following is very handy when finding all the files in the current directory which have been modified within 1 day.
# find -type f -mtime -1
But the above interpretation is simply wrong!
The real meaning of the above command is: Find all the files in the current directory which have been modified less than 2 days.
So if a file is modified before 1.9999999.. day, it still match the above command since the fractional part is ignored.
Try it yourself if you don't believe.
Reference:
man find
Remove empty lines in a file
Answer
Pick any one of the following methods.
1. grep
grep . test.txt
2. sed
sed '/^$/d' test.txt
3. awk
awk NF test.txt
4. tr
cat test.txt | tr -s "\n"
5. perl
perl -n -e 'print unless /^$/' test.txt
Change to the home directory in Linux
Answer:
To quickly change to the current user's home directory in Linux, you just need to remember the commabd cd ~
E.g.
# cd ~
pwd
/home/john
How to list directories in Linux?
Answer:
To list directories in Linux using command.
# ls -d /tmp