Daily Use Linux Commands
- cat – display or concatenate files
- cd – change directory
- chmod – change the permissions on a file or directory
- compress – compress a file
- cp – copy a file
- date – display the current date and time
- diff – display differences between text files
- echo – echo arguments to the standard
- output file – determine the type of a file
- find – find files of a specified name or type
- finger – display information about a user
- ftp – file transfer program
- grep – searches files for a specified string or expression
- kill – kill a process
- lpr – print out a file l
- s – list names of files in a directory
- man – display an on-line manual page
- mkdir – make a directory
- more – scan through a text file page by page
- mv – move or rename files or directories
- nice – change the priority at which a job is being run
- passwd – change your password ps – list processes
- pwd – display the name of your current directory
- quota – disk quota and usage
- rm – remove files or directories
- rmdir – remove a directory
- sort – sort and collate lines
- talk – talk to another user
- wc – display a count of lines, words and characters
How to Get Two Top Duplicate Records
I have been asked the same question in an interview. How to get 2 top duplicate records?
Sort file1 |unique -d | head -2
What this command does…
- Sorts File
- Display duplicate records
- Top 2 duplicate records
Count Number of Lines in a List of Files Using For Loop
#!/bin/bash if [ $# -lt 1 ] then echo "Usage: $0 file ..." exit 1 fi
echo "$0 counts the lines of code"
l=0
n=0
s=0
for f in $*
do
l=wc -l $f | sed 's/^\([0-9]*\).*$/\1/'
echo "$f: $l"
n=$[ $n + 1 ]
s=$[ $s + $l ]
done
echo "$n files in total, with $s lines in total"
Related Posts