Commands/: Get The Description For A Command
Commands/: Get The Description For A Command
http://www.smashingmagazine.com/2012/01/23/introduction-to-linuxcommands/
http://linuxcommand.org/
http://www.freeos.com/guides/lsst/
http://manuals.bioinformatics.ucr.edu/home/linux-basics
Get the description for a command (google search is easier! )
Man <commandname>
upgrade a software
sudo apt-get upgrade softwarename
Clean the local repository of downloaded package files, clearing disk space.
sudo apt-get clean
NOTE: All configuration files for linux are stored in a simple text file. That text file is:
/etc/passwd
Changing password
sudo passwd <username>
Special features?
Basically, the "special feature" is the ability to give the user the special ability to automatically change
users or group, or to specify a directory as a "temporary" directory.
The "s" above for the group (middle) settings shows that the "sticky" or "setgid" bit is set. This means that
any user who changes into that directory suddenly performs all actions as if the "webmasters" group was
their default group. This can be helpful if you want all files in that directory to be created owned by that
webmasters group.
The "s" flag can also be set for the user, which makes the user "sticky" or "setuid". This is not usually a
good idea, so don't do it unless you really know what you're doing.
The "t" flag is basically the same thing as the "s" flag for user or group, but is used when applied to all
others. Here, the meaning is a little different. It means that anyone can create a file in the directory, but
only the owner is allowed to remove the file, regardless of permissions set. This is the "temporary"
directory permission and should also be avoided unless you really know what you're doing.
Sticky bit
In computing, the sticky bit is a user ownership access right flag that can be assigned
to files and directories on Unix-like systems.
When a directory's sticky bit is set, the filesystem treats the files in such directories in a special way
so only the file's owner, the directory's owner, or root user can rename or delete the file. Without the
sticky bit set, any user with write and execute permissions for the directory can rename or delete
contained files, regardless of the file's owner. Typically this is set on the /tmp directory to prevent
ordinary users from deleting or moving other users' files.
Back to chmod
chmod actually has a couple ways to be used. There's a "named mode" which is a little easier to
comprehend and there's a "numeric mode" which exposes a little more of the guts.
Named Mode
Here we give names to all the involved parties. They come in two parts, a "who" and a "what."
who
u change the user bits
g change the group bits
o change the other bits
a change the bits for everybody
what
r
Examples
$ chmod a+r file.txt
This will allow everybody to read file.txt.
The -l stands for log in as, and your user name goes after it. If SSH is allowed, then it will ask
for a password.
The * wildcard
The character * is called a wildcard, and will match against none or more character(s) in a file
(or directory) name. For example, in your unixstuff directory, type
ls list*
This will list all files in the current directory starting with list....
ls *list
This will list all files in the current directory ending with ....list
The ? wildcard
The character ? will match exactly one character.
So ?ouse will match files like house and mouse, but not grouse.
% ls ?list
list directory
ls
Change the ownership to newuser and group to newgroup for all of the files and directories in
current directory, and all subdirectories (recursively).
$ chown -R newuser:newgroup .
The who command prints information about all users who are
currently logged in.
who
"less" writes the contents of a file onto the screen a page at a time.
less science.txt
wc (word count)
A handy little utility is the wc command, short for word count. To do a word count
on science.txt, type
wc -w science.txt
show just the first few or last few lines of a file with
the head and tailcommands. (It shows 10 lines by default, but you can pass in
any number)
head index.html
tail -20 index.html
to copy files
cp index.html indexold.html
http://www.hypexr.org/linux_scp_help.php
http://www.garron.me/en/linux/scp-linux-mac-command-windows-copy-files-over-ssh.html
http://unix.stackexchange.com/questions/2857/ssh-easily-copy-file-to-local-system
http://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/
If you just give it a directory, it will list everything that the directory contains.
find /var/www
If you have many websites, it could continue for a couple of minutes. You can stop it by hitting
Control + C. Thats the way to interrupt a Linux command.
The pipe symbol (|) takes the output of one command (in this case, the long list of files
produced by find) and passes it to another command (in this case, more, which shows you
one page of files at a time). As above, press the space bar to show the next page, and Q to quit.
find /var/www | more
To search for a specific file name, add -name and the file name. You can use * as a wild card (the
backslash is not always necessary but is good practice with the find command). You can combine
searches using -o (for or). If you leave out the -o, it becomes an and.
find /var/www -name "logo.gif"
find /var/www -name "*.gif"
find /var/www -name "*.gif" -o -name "*.jpg"
search by size
looking for all GIFs between 5 and 10 KB:
find /var/www -name "*.gif" -size +5k -size -10k
search by change
to find a file that was last changed between 90 and 180 days ago
find /var/www -name "*.gif" -ctime +90 -ctime -180
In both of these cases, you will probably also want to know the actual file size and date last
changed. For this, you can add -printf, which is similar to the C function printf in that you use
the % sign to output various information. This command outputs the file size (up to 15 characters
wide), the date and time changed (down to the nanosecond) and the file name:
find /var/www -name "*.gif" -size +5k -size -10k -ctime +90 -ctime -180 -printf "%10s
%c %p\n"
-cmin
Lets you see files that have changed in the last few minutes. If something goes wrong on a
website, you can run this to see everything that has changed in the last 10 minutes:
find /var/www -cmin -10 -printf "%c %pn"
This will show files and directories that have changed. Thus, it wont show files that have been
removed (because they are no longer there), but it will show the directories that they were
removed from. To show only files, add -type f:
find /var/www -cmin -10 -type f -printf "%c %pn"
You can use the -r option with a directory at the end, instead of a list of files. The single dot tells
it to start in the current directory.
grep -r "<div id="left">" .
You can also add -n to show the line numbers, as in this example:
grep -n "<div id="\content\">" *.php
Alternatively, you could use the find command from above to tell it which files to look in. To put
a command within a command, enclose it in back apostrophes. The following searches only for
the HTML in PHP files modified in the last 14 days:
grep "<div id="left">" `find . -name *.php -ctime -14`
fix an error
To do that, you will need to start up a Linux text editor. Different editors are available, such
as pico and emacs, but the one that is guaranteed to be there is vi. To edit a file, type vi and the
file name:
vi index.php
vim index.php //improved one!
To delete a character, press X. To delete a whole line, press DD. To insert a new character, press
I. This takes you into insert mode, and you can start typing. Press the Escape key when
finished to go back to command mode. Within command mode, type :w to save (i.e. write) the
file and :q to quit, or :wq to do both at the same time.
File Permissions
The list of user names (and, thus, potential file owners) on a UNIX system is stored in the file
/etc/passwd. You can try:
more /etc/passwd
The Apache Web server is started by a command when the Web server boots up. But the
user who starts Apache is often a restricted and unprivileged user, such as nobody or apache or
www-data. This is for security reasons, to prevent someone from hacking into the website and
then gaining control of the whole server. You can find out who that user is by running the
command below and looking in the first column. The ps aux command shows all of the
processes running on the server, and grep shows only processes that contain the word
apache.
ps aux | grep apache
If you upload a file to a website via FTP and log in as admin, then the file will be owned
by admin. If Apache was started by the user named nobody, then Apache might not be able to
read that file and wont be able to send it to any users who request it when viewing the
website. Instead, users will see a broken image or a message such as 403 Forbidden. You
dont have permission to access that file.
A subtler and more common problem is when an image can be viewed but not overwritten
or removed via the websites content management system (CMS). In this case, the
user nobody can read the file but cant write to it.
Other people who use the server have user accounts and might share the same
group with your user account.
The main difference between these two is in how the Web server runs.
Heres what were trying to achieve with this set of permission modes:
WordPress (via our Web server) may read and modify our scripts.
How to check which Apache group I can use for the web
server to write?
Apache runs as the www-data user but it can be different.
Use
ps aux | grep httpd
or
ps aux | grep apache
to see what user Apache is using on your system (The first column is apache)
http://stackoverflow.com/questions/18817744/chmod-all-files-to-644-andall-folders-to-755-of-a-dictory
xargs clarification: xargs breaks the list of arguments into sublists small enough to be
acceptable.
rm `find /path -type f`
will fail with an error message of "Argument list too long" (meaning that the exec system call's limit on the
length of a command line was exceeded) if there are too many files in /path .
However, the version below (functionally equivalent to rm `find /path -type f` ) will not fail:
find /path -type f -print0 | xargs -0 rm
OR
You can use grep -ilR:
grep -Ril "text-to-find-here" /
i stands for upper/lower case (optional in your case).
R stands for recursive.
l stands for "show the file name, not the result itself`.