Changing permissions of a file.
To add executable permissions for all categories of a file, you would use chmod a+x foo. To add executable permissions for only the current user, you would use:
chmod go-wx foo
Or you could usechmod +x:
chmod +x foo
That is a simpler way of achieving this. If you have compiled a simple program and you want to to be accessible only for your user, you may copy the binary into the ~/bin folder under your home directory and then it will be accessible anytime.
To set the permissions on the file so that the user and group categories are given the executable flag and permissions for other users are left untouched, then you would use:
chmod ug=x foo
If you wish to set permissions recursively in a directory and all subdirectories so that:
- the owner has read-write and execute permissions;
- the group has read and execute permission;
- other users do not have any permission to access the object at all;
you would use the command:
chmod -R u=rwx,g=rx,o=~/mystuff/
Copying and moving files.
Using wildcards. The * wildcard in action, copying the contents of one folder to another:
cp old/* new
if the folder you are copying to is outside the folder you are currently in you would use this syntax:
cp old/* ../new
This tells the shell that the folder you are copying to is outside the folder you are in. To copy only jpg files from the folder to the other folder use this syntax:
cp 4chan/*.jpg ../Wallpapers/
Listing files on the command-line.
The ls command is used to list files on the Linux command-line. To list files in your home directory including hidden files, use this command:
to list all files in a list format use this command:
To send the output of the ls command to a text file for easy perusal later, use this command:
ls -hula > file.txt
Then you may print this file or read it later in a text editor. If you use this command, then the output will be added to the end of the file if it already exists.
ls -hula >> file.txt
If the output of a command scrolls off the screen and you wish to be able to scroll through the output easily, this command will help:
ls -hula | less
This will send the output of the command to the less pager, allowing you to scroll through the output with the arrow keys.
Unpacking a tar.gz file
Many programs and other files for Linux come in a tar.gz file. To unpack these files is very easy:
tar -xvf jazip_0.34.orig.tar.gz
To unpack a tar.bz2 file that has been compressed with bzip, use this command:
tar -jxvf libvorbis-1.3.2.tar.bz2