chmod:
The chmod command allows you to alter access rights to files and directories. All files and directories have security permissions that grant the user particular groups’ or all other users’ access. To view your files' settings, at the shell prompt type: ls -altYou should see some files with the following in front of them (an example follows):total 4drwxrwsr-x 7 reallyli reallyli 1024 Apr 6 14:30 .drwxr-s--x 22 reallyli reallyli 1024 Mar 30 18:20 ..d-wx-wx-wx 3 reallyli reallyli 1024 Apr 6 14:30 contentdrwxr-xr-x 2 reallyli reallyli 1024 Mar 25 20:43 filesWhat do the letters mean in front of the files/directories mean?r indicates that it is readable (someone can view the file’s contents)w indicates that it is writable (someone can edit the file’s contents)x indicates that it is executable (someone can run the file, if executable)- indicates that no permission to manipulate has been assignedWhen listing your files, the first character lets you know whether you’re looking at a file or a directory. It’s not part of the security settings. The next three characters indicate Your access restrictions. The next three indicate your group's permissions, and finally other users' permissions.
Use chmod followed by the permission you are changing. In very simple form this would be: chmod 755 filenameThe example above will grant you full rights, group rights to execute and read, and all others access to execute the file.
Permission
7 full
6 read and write
5 read and execute
4 read only
3 write and execute
2 write only
1 execute only
0 none
like Typing the command: chmod 751 filename
gives you full access, the group read and execute, and all others execute only permission.
cp:
Type cp followed by the name of an existing file and the name of the new file. Ex:cp newfile newerfile To copy a file to a different directory (without changing the file’s name), specify the directory instead of the new filename. Ex:cp newfile testdir To copy a file to a different directory and create a new file name, you need to specify a directory/a new file name. Ex:cp newfile testdir/newerfile cp newfile ../newerfile The .. represents one directory up in the hierarchy.
file:
Type file followed by the name of an existing file in the directory. Ex:file emergency3_demo.exeOUTPUT: MS-DOS executable (EXE)This command allows you to figure out what the file type is and how to use it. For instance the command will tell you whether it is an executable, a compressed file and which type, or something unusual. This command is simplistic, but often can allow you to determine why a file does not respond the way you expect.
mv:
Type mv followed by the current name of a file and the new name of the file. Ex:mv oldfile newfile
Type mv followed by the name of a file and the new directory where you'd like to place the file. Ex:mv newfile testdir This moves the file named newfile to an existing directory named testdir. Be certain you’re specifying a directory name or the mv command alters the name of the file instead of moving it.
rm:
Type rm followed by the name of a file to remove the file. Ex:rm newfile Use the wildcard character to remove several files at once. Ex:rm n* This command removes all files beginning with n.Type rm -i followed by a filename if you’d like to be prompted before the file is actually removed. Ex:rm -i newfile rm -i n* By using this option, you have a chance to verify the removal of each file. The -i option is very handy when removing a number of files using the wildcard character *.
Wednesday, October 10, 2007
Linux Advanced Commands
du:
The du command prints a summary of the amount of information you have stored in your directories on the mounted disks.
syntax: du [options] pathex: du -a /NewsOptions:-s print the sum of bytes in your directories-a print a line for each file in your directory
grep:
The grep command searches text files for a particular word or string of words. Very helpful when trying to find that needle in a haystack, like a particular line in a large log file.syntax: grep textstring filename(s)ex: grep century history.text.doc
Head
Tail
head: prints the beginning of a text filetail: prints the end of a text fileThese commands allow you to view parts of a text file.tail -n 5 textfile.txt head -n 5 textfile.txtThe examples above will print the last 5 lines of the file textfile.txt and then the first 5 lines.
locate:
Trying to find out where on your Linux server a particular file resides? Having a real nasty time doing it? If you have the Bash shell you can try using the locate command to identify where it is on your mounted drives. Type: locate filename and press enter. Replace filename with the name of the file you are looking for. This is a real time saving command as you start navigating your Linux server!If locate does not work for you try using which.
Nice
Nohup
Nice: runs programs/commands at a lower system priorityNohup: runs nice programs even when you’re logged off the systemBy using the two commands simultaneously, your large processes can continue to run, even when you have logged off the system and are relaxing. Ex: nice nohup c program.c . This command will allow the c compiler to compile program.c even when you have logged off the system.
ps
related to "stopped jobs"
The ps command displays all of the existing processes. This command is also directly linked to issues with stopped processes (also known as "stopped jobs").Occasionally, you may see the message There are Stopped Jobs.If you log off the system without properly stopping your jobs, some jobs/processes may remain in memory tying up the system and drawing unnecessary processing bandwidth. Type ps and hit enter. This will list all of your current processes running, or stopped.PID TT STAT TIME COMMAND23036 pl S 0:00 -csh23070 pl R 0:00 viThe number under PID is the process identification number. To kill a process that is stopped, type: kill pid. Replace pid with the exact number of the process. Ex: While in Vi, you accidentally press the wrong keys. Vi's operation is stopped and you are kicked back to the prompt. To kill the stopped Vi command, you may type: kill 23070.
stty
The stty command allows you to view a listing of your current terminal options. By using this command, you can also remap keyboard keys, tailoring to your needs. Ex: stty and hit enter. This lists your terminal settings.Ex: stty erase\^h . This remaps your erase key (backspace) to the Ctrl and h keys. From now on, holding down Ctrl and pressing h will cause a backspace. So you're scratching your head asking why is this handy? You'll see at some point how stty is also used for a number of other useful settings.
talk
In order to contact someone who is on the system, at the prompt you type: talk accountname . Replace accountname with the full account name of the person. If you don’t want anyone to disturb you using the talk command, at the prompt type: mesg n. This prevents others from using talk to reach you.
tar
also related to gzip
You're bound to come across files that are g-zipped and tarred. Okay, now what? These are methods of compressing and storing directories and files in a single "file." Most new Linux programs come off the web as something like coolnew-game.4-4-01.gz. This file is likely a tar file that has then been gzipped for compression. The way to handle these files is simple, but requires that you put the file into an appropriate directory. In other words, don't plop the file in your root or /bin unless it belongs there.
Now you can do a one fell swoop un-gzip it and untar it into its original form (usually multiple files in many sub directories) by typing: tar -xvzf *.gzThis will programmatically un-gzip and then untar all files in the current directory into their full original form including sub-directories etc. Please be careful where and how you run this!
w
This command allows you to list all users’ and their processes who are currently logged in to the Linux server, or a particular user’s processes. Type: w to view all users’ processes. Type: w jsmith to view jsmith’s processes. We use this all the time from a system admin standpoint. Please also see more commands to get user information on this page. You need to know who logs on to your system! Okay, so you have a stand alone Linux box and no one else uses it? Try this command just to be sure. ;)
!!
Don’t waste time and energy retyping commands at the prompt. Instead, use the ! option. To automatically re-display the last command you typed at the prompt, type: !! and press enter. Press again to invoke the command. You can also automatically re-display a command you typed earlier by using the ! and the first few letters of the command. Ex: At the Linux prompt you had typed the command clear, followed by the command pico, followed by the command ftp. In order to re-display the clear command you type: !cl and press enter. In order to re-display the last command you typed, simply type: !! .
The du command prints a summary of the amount of information you have stored in your directories on the mounted disks.
syntax: du [options] pathex: du -a /NewsOptions:-s print the sum of bytes in your directories-a print a line for each file in your directory
grep:
The grep command searches text files for a particular word or string of words. Very helpful when trying to find that needle in a haystack, like a particular line in a large log file.syntax: grep textstring filename(s)ex: grep century history.text.doc
Head
Tail
head: prints the beginning of a text filetail: prints the end of a text fileThese commands allow you to view parts of a text file.tail -n 5 textfile.txt head -n 5 textfile.txtThe examples above will print the last 5 lines of the file textfile.txt and then the first 5 lines.
locate:
Trying to find out where on your Linux server a particular file resides? Having a real nasty time doing it? If you have the Bash shell you can try using the locate command to identify where it is on your mounted drives. Type: locate filename and press enter. Replace filename with the name of the file you are looking for. This is a real time saving command as you start navigating your Linux server!If locate does not work for you try using which.
Nice
Nohup
Nice: runs programs/commands at a lower system priorityNohup: runs nice programs even when you’re logged off the systemBy using the two commands simultaneously, your large processes can continue to run, even when you have logged off the system and are relaxing. Ex: nice nohup c program.c . This command will allow the c compiler to compile program.c even when you have logged off the system.
ps
related to "stopped jobs"
The ps command displays all of the existing processes. This command is also directly linked to issues with stopped processes (also known as "stopped jobs").Occasionally, you may see the message There are Stopped Jobs.If you log off the system without properly stopping your jobs, some jobs/processes may remain in memory tying up the system and drawing unnecessary processing bandwidth. Type ps and hit enter. This will list all of your current processes running, or stopped.PID TT STAT TIME COMMAND23036 pl S 0:00 -csh23070 pl R 0:00 viThe number under PID is the process identification number. To kill a process that is stopped, type: kill pid. Replace pid with the exact number of the process. Ex: While in Vi, you accidentally press the wrong keys. Vi's operation is stopped and you are kicked back to the prompt. To kill the stopped Vi command, you may type: kill 23070.
stty
The stty command allows you to view a listing of your current terminal options. By using this command, you can also remap keyboard keys, tailoring to your needs. Ex: stty and hit enter. This lists your terminal settings.Ex: stty erase\^h . This remaps your erase key (backspace) to the Ctrl and h keys. From now on, holding down Ctrl and pressing h will cause a backspace. So you're scratching your head asking why is this handy? You'll see at some point how stty is also used for a number of other useful settings.
talk
In order to contact someone who is on the system, at the prompt you type: talk accountname . Replace accountname with the full account name of the person. If you don’t want anyone to disturb you using the talk command, at the prompt type: mesg n. This prevents others from using talk to reach you.
tar
also related to gzip
You're bound to come across files that are g-zipped and tarred. Okay, now what? These are methods of compressing and storing directories and files in a single "file." Most new Linux programs come off the web as something like coolnew-game.4-4-01.gz. This file is likely a tar file that has then been gzipped for compression. The way to handle these files is simple, but requires that you put the file into an appropriate directory. In other words, don't plop the file in your root or /bin unless it belongs there.
Now you can do a one fell swoop un-gzip it and untar it into its original form (usually multiple files in many sub directories) by typing: tar -xvzf *.gzThis will programmatically un-gzip and then untar all files in the current directory into their full original form including sub-directories etc. Please be careful where and how you run this!
w
This command allows you to list all users’ and their processes who are currently logged in to the Linux server, or a particular user’s processes. Type: w to view all users’ processes. Type: w jsmith to view jsmith’s processes. We use this all the time from a system admin standpoint. Please also see more commands to get user information on this page. You need to know who logs on to your system! Okay, so you have a stand alone Linux box and no one else uses it? Try this command just to be sure. ;)
!!
Don’t waste time and energy retyping commands at the prompt. Instead, use the ! option. To automatically re-display the last command you typed at the prompt, type: !! and press enter. Press again to invoke the command. You can also automatically re-display a command you typed earlier by using the ! and the first few letters of the command. Ex: At the Linux prompt you had typed the command clear, followed by the command pico, followed by the command ftp. In order to re-display the clear command you type: !cl and press enter. In order to re-display the last command you typed, simply type: !! .
Linux Beginner Commands
arp:
Used for checking existing Ethernet connectivity and IP address
This command should be used in conjunction with the ifconfig and route commands. It is mostly useful for me to check a network card and get the IP address quick.
df:
Display filesystem information
df -h
show how much hard disk space you have on each mounted file system.
du:
Display usage
Most common use, under a specific directory: du -a
find:
Find locations of files/directories quickly across entire filesystem
Most common use: find / -name filename -type d -xdev (replace the word filename with the name of a file or application)
ifconfig:
Command line tool to configure or check all network cards/interfaces
init:
Allows you to change the server bootup on a specific runlevel
joe or nano
Easy to use command line editors that are often included with the major Linux flavors
Most common uses:joe filename nano filename
netstat:
Show the summary of network connections and status of sockets
Most common uses: netstat and also netstat head and also netstat -r
Netstat command simply displays all sockets and server connections. The top few lines are usually most helpful regarding webserver administration. Therefore if you are doing basic webserver work, you can quickly read the top lines of the netstat output by including the head (pipe and head commands). Using the -r option gives you a very good look at the network routing addresses. This is directly linked to the route command.
nslookup:
Checks the domain name and IP information of a server
ping:
Sends test packets to a specified server to check if it is responding properly
This is an extremely useful command that is necessary to test network connectivity and response of servers. It creates a series of test packets of data that are then bounced to the server and back giving an indication whether the server is operating properly.
It is the first line of testing if a network failure occurs. If ping works but for instance FTP does not, then chances are that the server is configured correctly, but the FTP daemon or service is not. However, if even ping does not work there is a more significant server connectivity issue… like maybe the wires are not connected or the server is turned off! The outcome of this command is pretty much one of two things. Either it works, or you get the message destination host unreachable. It is a very fast way to check even remote servers.
ps:
Lists all existing processes on the server
Most common uses: ps and also ps -A more
The simple command will list every process associated with the specific user running on the server. This is helpful in case you run into problems and need to for instance kill a particular process that is stuck in memory. On the other hand, as a system administrator, I tend to use the -A with the more option. This will list every process running on the server one screen at a time. I use it to quickly check what others are goofing with on my servers and often find that I'm the one doing the dangerous goofing!
rm
Removes/deletes directories and files
Most common use: rm -r name (replace name with your file or directory name)
The -r option forces the command to also apply to each subdirectory within the directory. For instance if you are trying to delete the entire contents of the directory x which includes directories y and z this command will do it in one quick process. That is much more useful than trying to use the rmdir command after deleting files! Instead use the rm -r command and you will save time and effort. You may already have known this but since server administrators end up spending a lot of time making and deleting I included this tip!
route:
Lists the routing tables for your server
Most common use: route -v
This is pretty much the exact same output as the command netstat -r. You can suit yourself which you prefer to run. I tend to type netstat commands a lot more than just route and so it applies less to my situation, but who knows, maybe you are going to love and use route the most!
shred
Deletes a file securely by overwriting its contents
Most common use: shred -v filename (replace filename with your specific file)
The -v option is useful since it provides extra view of what exactly the shred tool is doing while you wait. On especially BIG files this could take a bit of time. The result is that your file is so thoroughly deleted it is very unlikely to ever be retrieved again. This is especially useful when trying to zap important server related files that may include confidential information like user names or hidden processes. It is also useful for deleting those hundreds of love notes you get from some of the users on your server, another bonus of being a server administrator. :)
sudo:
The super-user do command that allows you to run specific commands that require root access.
Most common use: sudo command (replace command with your specific one)
This command is useful when you are logged into a server and attempt a command that requires super-user or root privileges. In most cases, you can simply run the command through sudo, without having to log in as root. In fact, this is a very beneficial way to administer your server without daily use of the root login, which is potentially dangerous.Below is a simple example of the sudo capabilities:sudo cd /rootThis command allows you to change directories to the /root without having to login as root. Note that you must enter the root password once, when running a sudo command.
top:
Displays many system statistics and details regarding active processes
Most common use: top
This is a very useful system administrator tool that basically gives you a summary view of the system including number of users, memory usage, CPU usage, and active processes. Often during the course of a day when running multiple servers, one of my Xwindows workstations just displays the top command from each of the servers as a very quick check of their status and stability.
touch:
Allows you to change the timestamp on a file.
Most common use: touch filename
Using the basic touch command, as above, will simply force the current date and time upon the specified file. This is helpful, but not often used.However, another option that I've used in the past when administering servers, is to force a specific timestamp on a set of files in a directory.
traceroute:
Traces the existing network routing for a remote or local server
Most common use: traceroute hostname
w
An extension of the who command that displays details of all users currently on the server
Most common uses: w
This is a very important system admin tool I use commonly to track who is on the server and what processes they are running. It is obviously most useful when run as a superuser.
The default setting for the w command is to show the long list of process details. You can also run the command w -s to review a shorter process listing, which is helpful when you have a lot of users on the server doing a lot of things! Remember that this is different than the who command that can only display users not their processes.
who:
Tool used to monitor who is on the system and many other server related characteristics
Most common uses: who and also who -q and also who -b
Used for checking existing Ethernet connectivity and IP address
This command should be used in conjunction with the ifconfig and route commands. It is mostly useful for me to check a network card and get the IP address quick.
df:
Display filesystem information
df -h
show how much hard disk space you have on each mounted file system.
du:
Display usage
Most common use, under a specific directory: du -a
find:
Find locations of files/directories quickly across entire filesystem
Most common use: find / -name filename -type d -xdev (replace the word filename with the name of a file or application)
ifconfig:
Command line tool to configure or check all network cards/interfaces
init:
Allows you to change the server bootup on a specific runlevel
joe or nano
Easy to use command line editors that are often included with the major Linux flavors
Most common uses:joe filename nano filename
netstat:
Show the summary of network connections and status of sockets
Most common uses: netstat and also netstat head and also netstat -r
Netstat command simply displays all sockets and server connections. The top few lines are usually most helpful regarding webserver administration. Therefore if you are doing basic webserver work, you can quickly read the top lines of the netstat output by including the head (pipe and head commands). Using the -r option gives you a very good look at the network routing addresses. This is directly linked to the route command.
nslookup:
Checks the domain name and IP information of a server
ping:
Sends test packets to a specified server to check if it is responding properly
This is an extremely useful command that is necessary to test network connectivity and response of servers. It creates a series of test packets of data that are then bounced to the server and back giving an indication whether the server is operating properly.
It is the first line of testing if a network failure occurs. If ping works but for instance FTP does not, then chances are that the server is configured correctly, but the FTP daemon or service is not. However, if even ping does not work there is a more significant server connectivity issue… like maybe the wires are not connected or the server is turned off! The outcome of this command is pretty much one of two things. Either it works, or you get the message destination host unreachable. It is a very fast way to check even remote servers.
ps:
Lists all existing processes on the server
Most common uses: ps and also ps -A more
The simple command will list every process associated with the specific user running on the server. This is helpful in case you run into problems and need to for instance kill a particular process that is stuck in memory. On the other hand, as a system administrator, I tend to use the -A with the more option. This will list every process running on the server one screen at a time. I use it to quickly check what others are goofing with on my servers and often find that I'm the one doing the dangerous goofing!
rm
Removes/deletes directories and files
Most common use: rm -r name (replace name with your file or directory name)
The -r option forces the command to also apply to each subdirectory within the directory. For instance if you are trying to delete the entire contents of the directory x which includes directories y and z this command will do it in one quick process. That is much more useful than trying to use the rmdir command after deleting files! Instead use the rm -r command and you will save time and effort. You may already have known this but since server administrators end up spending a lot of time making and deleting I included this tip!
route:
Lists the routing tables for your server
Most common use: route -v
This is pretty much the exact same output as the command netstat -r. You can suit yourself which you prefer to run. I tend to type netstat commands a lot more than just route and so it applies less to my situation, but who knows, maybe you are going to love and use route the most!
shred
Deletes a file securely by overwriting its contents
Most common use: shred -v filename (replace filename with your specific file)
The -v option is useful since it provides extra view of what exactly the shred tool is doing while you wait. On especially BIG files this could take a bit of time. The result is that your file is so thoroughly deleted it is very unlikely to ever be retrieved again. This is especially useful when trying to zap important server related files that may include confidential information like user names or hidden processes. It is also useful for deleting those hundreds of love notes you get from some of the users on your server, another bonus of being a server administrator. :)
sudo:
The super-user do command that allows you to run specific commands that require root access.
Most common use: sudo command (replace command with your specific one)
This command is useful when you are logged into a server and attempt a command that requires super-user or root privileges. In most cases, you can simply run the command through sudo, without having to log in as root. In fact, this is a very beneficial way to administer your server without daily use of the root login, which is potentially dangerous.Below is a simple example of the sudo capabilities:sudo cd /rootThis command allows you to change directories to the /root without having to login as root. Note that you must enter the root password once, when running a sudo command.
top:
Displays many system statistics and details regarding active processes
Most common use: top
This is a very useful system administrator tool that basically gives you a summary view of the system including number of users, memory usage, CPU usage, and active processes. Often during the course of a day when running multiple servers, one of my Xwindows workstations just displays the top command from each of the servers as a very quick check of their status and stability.
touch:
Allows you to change the timestamp on a file.
Most common use: touch filename
Using the basic touch command, as above, will simply force the current date and time upon the specified file. This is helpful, but not often used.However, another option that I've used in the past when administering servers, is to force a specific timestamp on a set of files in a directory.
traceroute:
Traces the existing network routing for a remote or local server
Most common use: traceroute hostname
w
An extension of the who command that displays details of all users currently on the server
Most common uses: w
This is a very important system admin tool I use commonly to track who is on the server and what processes they are running. It is obviously most useful when run as a superuser.
The default setting for the w command is to show the long list of process details. You can also run the command w -s to review a shorter process listing, which is helpful when you have a lot of users on the server doing a lot of things! Remember that this is different than the who command that can only display users not their processes.
who:
Tool used to monitor who is on the system and many other server related characteristics
Most common uses: who and also who -q and also who -b
Subscribe to:
Posts (Atom)