Check the system kernel version:
uname -a
cat /proc/version
lsb_release -a
To copy a folder and exclude a folder within. I use to this to copy git project from place to another git server.
rsync -av --progress sourcefolder /destinationfolder --exclude thefoldertoexclude
rsync -av --progress source/ path/to/dest/ --exclude .git
Check display settings:
xdpyinfo
View Bootup messages:
dmesg
Test DNS:
nslookup
ex: nslookup http://www.yahoo.com
Diff between two folder to create patch:
Create a file (ignorefile) that contains file patterns to ignore:
*.o
~*
diff -X ignorefile -rupN original/ new/ > original.patch
-r When comparing directories, recursively compare any subdirecto- ries found. -u Use the unified output format. -p Show which C function each change is in. -N --new-file In directory comparison, if a file is found in only one direc- tory, treat it as present but empty in the other directory. --exclude=pattern When comparing directories, ignore files and subdirectories whose basenames match pattern.
When using –exclude, put only the subfolder name, not the entire path.
For instance, when comparing linux kernel, if want to exclude /arch/alpha do –exclude=alpha; –exclude=/arch/alpha does not work
Resource:
http://stackoverflow.com/questions/33073/ignore-emacs-auto-generated-files-in-a-diff
Find file:
find [path location] -[name|iname] "search term"
ex:
find . -iname "gli" - find file case insensitive from current path gli
find / -name "glu*" - find file case senstive from '/' path of all files starting with 'glu'
Find file by time (src: coderwall)
find . -mmin
find . -mmin -5 modified in last 5 min
find . -cmin/ctime - created in min/days
find . -amin/atime - accessed in min/days
Reference:
http://www.theunixschool.com/2012/07/find-command-15-examples-to-exclude.html
Searching for a string in a file:
grep "search_string" filename - search string in file
grep -w "search_string" filename - Search for whole words only
grep -i "search_string" filename - case insensitive
grep -r "search_string" * - Searching in all files recursively
grep -r "search_string" --exclude="*.sql" * - Search exclude *.sql files
grep -r "search_string" --exclude-dir={"folder_1","folder_2"} * - Search exclude multiple folders
grep -r -i --include \*.js --include \*.php "search_string" -i - case-insensitive search --include=\*.${file_extension} - search files that match the extension(s) or file pattern only
References:
https://stackoverflow.com/questions/6565471/how-can-i-exclude-directories-from-grep-r
https://stackoverflow.com/questions/12516937/grep-but-only-certain-file-extensions
Size of current folder: CodeCofee link
du -sh # disk usage of current folder
du -shc * # disk usage of all top level directories + total sum
du -hc --max-depth=1 # disk usage of all top level directories + total sum
SVN
svn revert -R . - Revert all changes in current folder and subfolders link
To check out CPU utilization and memory utilization:
top
Common Tar commands:
tar zcvf archive.tar.gz
tar jcvf archive.tar.bz2
# Extract tar into a specific folder
tar xvf archive.tar.gz -C
tar -tvf file.tar.gz # list the contents of .tar
tar -ztvf file.tar.gz # list the contents of .tar.gz
tar zcvf archive.tar.gz . --exclude=folder1 #This will exclude folder1 (NO /)
To tar up a rootfs link
cd rootfs
sudo tar cvf /lxcrootfs.tar --exclude='lxcrootfs.tar' .
Change the achieve folder structure
http://stackoverflow.com/questions/939982/how-do-i-tar-a-directory-of-files-and-folders-without-including-the-directory-it
cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd ..
- unzip
unzip <FILE>.zip -d <DIRECTORY> Ex: unzip file.zip -d /opt/
Add user to existing group
sudo adduser
Change user’s primary group
sudo usermod -g