The Linux commands you need!

从网上看到的,还可以。挺基础的还有些技巧性的。

After half a year of linux, I have some post-it memo's sticked to my monitor with some commands that are really usefull, but that I keep forgetting (I forget a lot, that is why I write it down. Unlike people that think they are really cool because they can remember everything, I tend to think that all the great new impressions I get just need so much room, they push out others).

Right commands; there we go.. NEW some of these things have been stolen from [url]http://linux.oreilly.com/news/linuxnut_0800.html[/url]

Performance
What processes are running? ps waux | more The processes with k are kernel processes usually.
How is the load of your machine? vmstat 5 . The idle time is important . If this is 0 for long you might just have a problem. uptime also shows the load. Also try iostat, free, top.

Own your processes
have a good look at man ps to see what you can do. Nice are "ps wax" "ps waux" ps wauxwww" and so on.
Monitor what is going on by doing tail -f /var/log/messages . And you will see what logging is being produced.
Look at what files are open by using lsof . lsof -i for network, lsof -ujoe for all files for user joe and so on.

Own your disk
See where your diskspace is going with goign to / and doing du -s *. Then cd to the biggest space-eater and repeat this there and so on.
sort files by age with ls -lt. By size with ls -lSr . See man ls.

Own your network
look at your routes with netstat -r | more
Look at your interface with ifconfig
Look at open ports and so on with netstat -an or lsof -i
Look at interfaces with netstat -i eth0

alt-F2 and alt-F1 lets you switch between virtual consoles . Actually alt-Fn, where Fn is one of the function keys F1-F6. (If you are in X, you'll probably need to use Ctrl-Alt-Fn instead.) Alt+F7 gets you back to your X session, if one is running. You can rotate between consoles with the Alt-right arrow and Alt-left arrow key combinations. In this way you can kill a process in console two that has console 1 blocked.

locate lets you use an easier way to find files than the find command. In contrast to find's complexity, locate is the ultimate in simplicity. The command:

locate

searches an internal database and prints the pathnames of all files and directories that contain the given string in their names. You can narrow down the search by piping the output to grep. For example, the following finds all files containing the string "kde" that are in bin directories:

locate kde | grep bin

The strings don't have to be complete names; they can be partial strings, such as "gno" instead of spelling out "gnome". The -r option lets you use a regular e­xpression (in quotes):

locate -r 'gno*'

One thing to be aware of is that locate is case-sensitive: Searching for HOWTO and for howto will give you different results.

Rather than searching the disk each time, as find does, locate depends on the creation and maintenance of a database. Because it only has to search the database, not the disk, locate is faster than find. On the other hand, the results are only as current as the database.

The locate database is generally updated daily by a cron job, but you can update it manually by running the command updatedb (usually as root). If you are adding new applications or deleting old files and you don't want to wait for the next day to have an up-to-date database, you might want to run it manually.

If you want to use find however, to find a file crontab in /etc do :

find /etc -name crontab

find /etc -name cron*


tab will complete the prompt command for you, like url's in netscape and IE. So do /etc/-TAB- and you will get that file you also wanted before. Another tab and you will get the next one.

dmesg gets you to view startup messages . The dmesg command provides an easier way to see the boot messages than trying to read them before they scroll off the screen. When Linux boots, the kernel startup messages are captured in a buffer known as the kernel ring buffer; dmesg prints the contents of that buffer.

uname lets you find out what kernel version you are using. Do you ever need to know what version of the Linux kernel is running on your system? You can find out with the uname command, which prints information about the system. Issued with the -r option, uname prints the kernel version:

% uname -r

2.2.14-5.0

Other uname options provide information such as the machine type, the name of the operating system, and the processor. The --all option prints all the available information.


cntr-W (or ^W) lets you delete the complete command at the shell prompt. At this link you can find more of these tips. Most important:

^w erase word

^u erase from here to beginning of the line (I use this ALL the time.)

^a move the cursor to the beginning of the line

^e move the curor to the end of the line


!xyz lets you search the command history for commands with xyz as the beginning.

!xyz:p will show the command that would be executed rather than executing it.

!$ will repeat the last word of the last prompt command.So if you do pico /etc/ppp/ip-up and then pico !$ you will get the same result: the !$ expands to the last word of the last command so in this case to /etc/ppp/ip-up.

chkconfig will show you what programs and so on start at what runlevel with a redhat system. You can use chkconfig --list --add --del --level. With the delete you can het rid of those pesky deamons you don't need. Like pcmia when you do not have a laptop. Have a look at ask the geek 2 and here where it is all explained.

ifconfig gets you your ip number and so on, as well as the ip number of the gateway from your isp (internet provider you are dialing into are are hooked upto).

w Tells you who is logged in.

find /etc *.jpg This tries to find anything ending on jpg (pics) in the directory /etc and every subdirectory in /etc. You can change /etc and *.Jpg of course :-) Do man find to find out more.

crontab can be used to schedule things. first do

export VISUAL=pico

to make sure you can use the editro pico instead off the legacy-mistake shit editor VI (my opinion).
Then do
crontab -e
and you will see a temporary file where you can add commands. See man crontab and man cron for more.

The command
10 * * * * /etc/rc.d/init.d/adsl check
will schedule the command adsl check every 10 minutes. The * * are minutes; hours days months years I believe. Check out linuxnewbie . for more on this.

rpm stuff RPM lets you install and uninstall programs without compiling them . There are the essentials when doing this from the command prompt:
# rpm -q bc
asks the rpm manager if package bc is installed.


# rpm -e bc
uninstalls bc
-e means erase


# rpm -ihv bc-*.rpm
installs the package bc-......rpm
-i means install. H means show this ############# when installing
-v means verbose or in linux language give some info while youre busy.
So if you have a package cpp-4.3.2.3.rpm at /var/rpms you can install it by doing
rpm -ihv /var/rpms/cpp*.rpm
but you are better of to use (exept for kernells)
# rpm -Uvh /var/rpms/cpp*.rpm because this updates rather then installs. This is nice because if there is an old version the old stuff gets erased if you do not need it. also see here

df This tells you how much room you have on your linux disk partitions. Man df tells you more.

du This tells you how much diskspace is taken up by the directory you are standing in and the subdirectories when giving the command. To change directories do cd ..(to go up) and cd /etc to go for instance from root (/ ) to /etc. You can also do cd /etc/rc.d/ from anywhere.

netcfg This tells you how your routing table is doing, and what is in it.

whereis mam Tells you where the directory or file mam is.

whatis mam Tells you what mama is? A psychiater can tell you more as well as man whatis

which mam Forgot this one.

top Tells you things about memory status

ps ax Tells you what processe are running. Do man ps to find out more.

kill 1234 stops process 1234. Don't do this with process 1! 'ps ax' tells you what numbers processes have.

man ps > /tmp/manps.txt Writes a file 'manps.txt' or any other name you choose, with in that file what you see on screen when you do 'man ps' or any other command.

lpq Tells you what is in the printing que

lprm Cancel a print

Howto make a back up of say your /etc directory? Have you tried to read man tar? Boehoehoe!!!!! This is exactly why linux was not for common computer users. This kind of things really piss me of to a great extend. I would like those that wrote this man to go to hell and stay there. (sorry but I get really angry by such unreadable documents, without even a gew examples to explain how to do what a common personwould do with it).
So you want to backup /etc and all in it to /tmp huh? (thanks to Joe Burns from html goodies).
First you have to make a /tmp directory of course where you can write to. mdir /tmp or use your filebrowser. The rights have to be so that you can write to it as root, and read it as non-root. Be carefull because /etc contains your passwords. If anyone can go to the directory and read it then they can get to your passwords.
To back up do
tar cf /tmp/backup.tar /etc
tar means tape archive and that is based on those days when you did not toast everything on cd. or when your cd's are not big enough because you need to back up all the home directories of an entire organization like Intell :-)
c = create, f = targetfile, /etc = what you backup
If you want to compress it do tar czf /tmp/backup.tgz /etc
compressing is not that cool because if there is one mistake in the file it will be useless. So only compress if you need the space or if you got a lot to tar.
If you want to see what is going on do ' tar cvf /tmp/backup.tar /etc '
Test it by doing tar tf backup.tar
Unpack it by doing ' tar xf backup.tar ' STOP! Dont do this when you are in '/ ' because you will overwrite your original '/etc ' !!!!!!!!!
or if you also zipped it ' tar xzf backup.tgz '.
STOP! Dont do this when you are in / because you will overwrite your original '/etc' !!!!!!!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值