Linux Commands

Check the system kernel version:

uname -a
cat /proc/version

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 <website>

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 <TIME>                  – modified with TIME minutes -60

find . -mmin -5       modified in last 5 min

find . -cmin/ctime                         – created in min/days

find . -amin/atime                         – accessed in min/days

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

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

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 ..

 

 

 

 

To replace a file in the archive, you must delete the file from the archive and then add it:tar –delete -f archive.tar filetodelete
tar -rvfI don’t even understand these commands anymore
tar jcvf archieve.tar.bz2 -C .
For when you want to do
/path/to/archieve/file1
/path/to/archieve/file2
In the tar you want it to be file1, file2 not /path/to/archieve/file1,/path/to/archieve/file2
tar jcvf archieve.tar.bz2 -C /path/to/archieve .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s