tail a file
tail -100f FileName
-f to allow file monitoring
Another way is to watch file using
less +F FileName to wait for new data. use
ctrl+c to exit to the normal less mode to do search/page uptown etc. once down, we can hit
F again to the watch mode.
less only opens chunk of file so should be more memory friendly than
vim when opening large file. And its command set is very similar to
vi. The con is the syntax highlight is not that good comparing to
ps -f -p ThePID
-f full all columns
-p by process ID
ps -e -f
-e all processes
ps -ef | grep yourkeyword
to search for process
if the CMD is very long like running java command with long classpath and param. use
Wide output. Use this option twice for unlimited width.
tar -xvf YOUR.tar.gz
xf are required: The -x (for extract). The -f indicates that the next argument (i.e., piece of input data in a command) will be the name of the new archive file.
The -v (i.e., verbose) option is commonly used together with the -c/-x and -f options in order to display a list of the files that are included in the archive.
-c instructs tar to create an archive:
tar -cvf file.tar file1 file2 file3 OR tar -cf * to compress all.
The -t option tells tar to list the contents of an uncompressed archive without performing an extraction. Thus, the following would list the contents of file.tar:
tar -tf file.tar
More reference like delete/add file to tar.
rm to remove file. To remove non-empty directory:
rm -rf dirToBeRemoved/
- -r : Attempt to remove the file hierarchy rooted in each file argument i.e. recursively remove subdirectories and files from the specified directory.
- -f : Attempt to remove the files without prompting for confirmation, regardless of the file’s permissions
-h: human readable display
check directory/fold size
du -sh folderName
with out ‘s’, it would print out size recursively
to see all the directory and sort by size reversely:
du -sh * | sort -nr
find difference for two files
Option 1: diff -y file1 file2
-y will display output in two columns. More options about diff
-i is also handy when we want to ignore case
To get only diff, we can add a pipe and grep lines with ‘|’ like:
diff -y file1 file2 | grep -E ".*(\||>).*"
-E in grep means: Interpret PATTERN as an extended regular expression
Option2: grep -vf file1 file2
-v Invert the sense of matching, to select non-matching lines.
-f Obtain patterns from FILE, one per line.
so the above command will output the lines in file2 but not in file1. And we can run the reverse: grep -vf file2 file1 to get the lines in file1 but not in file2.
The first param could also be just a String like: ‘grep -v apple fruitList.txt’ will get all lines in fruitList.text that is not apple.
find string in current directory
grep -nir yourString* .
The dot at the end searches the current directory. Meaning for each parameter:
'-n' Show relative line number in the file 'yourString*' String for search '-r' Recursively search subdirectories listed '-i' ignore case '.' Directory for search (current directory)
find code line number
find . -type f -name "*.java" -or -name "*.xml" | xargs cat | wc -l
list who is listening a port
lsof -i :PORT_NUMBER
netstat -anp | grep PORT_NUMBER
and to kill these processes, just add -k:
fuser -k 10000/tcp
Shutdown and reboot
use ‘halt’ and ‘reboot’ to do shutdown/reboot in cmd.
replace all in VI
verfiy http/https connectivity
For general ip/port connectivity test, use nc(netcat)
nc -zv YourIp YourPort
-z : Specifies that nc should just scan for listening daemons, without sending any data to them. It is an error to use this option in conjunction with the -l option.
create link(ln) to file/directory
about make file immutable
chattr, we can make a file immutable or append-only. We can use
lsattr to view the attritbutes.