Posts Tagged linux
stop lose track with cp
Linux:
# -p to preserve ownership and permissions cp -p x y # even better if you have this alias in your .bashrc alias cp="cp -p"
When working in a team, it is very important to preserve the information when you copy files around. It is very easy to lose track where the files are from, and who owns it. When we have to make duplicate copies of the same thing, make sure you use “-p”.
do it in colour in bash
bash:
# many bash script supports coloured output, it really helps if you are searching # for something either a word or a directory from tens even hundreds of output ls --color grep --color
find all your files or directories on disk
bash:
# find all your files and directories find / -user user_name 2>/dev/null # find all your directories find / -user user_name -type d 2>/dev/null
list ports being used by which program
linux:
lsof -i -n -p
remote desktop access from linux
bash:
# remote desktop access to remote windows servers rdesktop rdp.remote.server.com
You may need to install rdesktop first from your favorite package manager. If you don’t know how to install it, you can find some instruction here
install sun-java in ubuntu
bash:
# add to repository list Ubuntu 10.4/10.10 sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" sudo apt-get update sudo aptitude install sun-java6-jdk sudo update-java-alternatives -s java-6-sun
change a number value in a text file
Posted by yifanz in text/data process on December 27, 2010
bash:
# this example will increase the integer value of a text file, e.g. value=1234 to value=1235 awk '/^value=/{ str=$0; sub("value=", "", str); n=strtonum(str); n++; print "value=" n; skip=1;} {if(!skip) {print $0;} skip=0;}'
remove / delete files using wildcard pattern when too many files in command line
bash:
# if we want to delete files whose names start with "tmp", normally we do as: rm tmp* # however, when there are too many files, bash will complain that there are too many files in list, then you can do find . -maxdepth 1 -name "tmp*" -delete # if you actually want to delete recursively, remove -maxdepth find . -name "tmp*" -delete
ldd to find out program’s dependences
linux:
# ldd can display which .so library the program will use ldd ./program
avoid accidental deletion by rm
bash:
# rm option -i will ask you every time it delete a file, you can also add this line to your .bashrc alias rm="rm -i" # in a research environment, most of time you have plenty of space, you can disable rm at all alias rm="echo"