Go back to the previous directory in shell
cd -
It goes back to the previous directory.
cd $OLDPWD
This can be also used in shell scripts.
cd -
cd $OLDPWD
| Command | Meaning |
|---|---|
| chmod 400 file | To protect a file against accidental overwriting. |
| chmod 500 directory | To protect yourself from accidentally removing, renaming or moving files from this directory. |
| chmod 600 file | A private file only changeable by the user who entered this command. |
| chmod 644 file | A publicly readable file that can only be changed by the issuing user. |
| chmod 660 file | Users belonging to your group can change this file, others don't have any access to it at all. |
| chmod 700 file | Protects a file against any access from other users, while the issuing user still has full access. |
| chmod 755 directory | For files that should be readable and executable by others, but only changeable by the issuing user. |
| chmod 775 file | Standard file sharing mode for a group. |
| chmod 777 file | Everybody can do everything to this file. |
ssh-keygen generate ssh keys*.pub can go into Github SSH keys or the remote computer's ~/.ssh/authorized_keys file.$ ssh-keygen -t rsa -f project-name -C "name@email.com"
ssh secure shellssh command. The 3 common ways that I have used are:~/.ssh/configHost projectname
HostName website.com
Port 8000
IdentityFile ~/.ssh/sshkey
IdentitiesOnly=yes
User username
$ ssh projectname
<!--emailoff-->$ ssh -i mykey.pem username@server.com<!--/emailoff-->
$ ssh projectname -t "cd /path/to/app ; /bin/bash"
scp secure copyscp comes in handy for transferring files from the local machine to the remote machine and vice versa.<!--emailoff-->$ scp -i /path/to/key.pem /path/to/file username@server.com<!--/emailoff-->
<!--emailoff-->$ scp -i ~/.ssh/key.pem /path/to/source/file username@server.com:~/path/to/destination/file<!--/emailoff-->
cp copy$ cp /path/to/source-folder/filename /path/to/destination-folder
$ cp -r /path/to/source-folder/folder /path/to/destination
$ cp /path/to/source-folder/filename /path/to/destination . # dot: destination is current folder
mv move$ mv /path/to/source-folder/filename . # move file to current directory
$ mv /path/to/source-folder . # move folder to current directory
echo output$ echo hello
$ echo `date` >> currentime.txt # copy to file
$ echo `date` > currentime.txt # append
touch update a filetouch will simply create a file.$ touch filename1 filename2 filename3
ln symlink$ ln -s /path/to/source/filename /path/to/destination/filename
head top of a filehead is very useful to quickly view a certain first few lines of a file with an option -n to specify how many lines from the top.$ head -n 5 /path/to/filename
tail end of a filetail as the name goes, is the opposite of the command head and this gives the content of the last lines of a file. Using with the option -f, the output is appended as the file grows and this is used to continuously view server log files while changes are happening.$ tail -n 5 /path/to/filename
$ tail -f log/production.log
cat see the contents of a filecat is a simple way to view the file contents, but it can also be used to concatenate a few files into a new file.$ cat /path/to/filename
$ cat file1 file2 >> newfile # newfile has contents of file1 and file2
chmod change permissionschmod can change these permissions with either a number or expression.$ chmod u+x /path/to/script # user can execute
$ chmod 600 ~/.ssh/authorized_keys # user can read, write
sudo act as rootsudo gives the permission to run commands as the root user. It can be used for a single command or a series of commands. This command should definitely be used with caution as root user will have permissions to execute things a normal user might not.$ sudo !! # execute the previous command with sudo
$ sudo cp /path/to/source /path/to/destination # execute as root
$ sudo su # switches from current user to root
chown own the folder/filechown comes in handy invarious situations.$ sudo chown -R username:username ~/path/to/folder
cd change directorycd:$ cd ~ # go to home directory
$ cd - # go to the last visited directory
$ cd ../path/to/folder # go to relative directory one level up
$ cd /path/to/folder # absolute path
ls list files/foldersls with 3 options are useful to view the dotfiles in long format to give a comprehensive look inside that folder.$ ls -lah . # current folder
$ ls -lah ~ # home folder
$ ls -lah /path/to/folder # absolute path to a folder
ps running processesps. Often, the list will be long. In this case piping the answer to a search terms is useful.$ ps aux | grep unicorn # find all unicorn processes
ps aux will give a long list of useful information about the processes including the user, CPU usage, path to the command as well as the Process ID (PID) which will come in handy if we want to stop that particular process.kill terminate a processps which will give the PID number, we can kill that particular process with a Unix signal 9. Here's an example:$ ps aux | grep jekyll
$ sayanee 1835 0.0 0.8 2509028 68756 s003 S+ 7:59PM 1:00.64 ruby /Users/command
$ kill -9 1835
lsoflsof comes in handy!$ sudo lsof -i:8080 # complete info on the process
$ sudo lsof -t -i:8080 # just the PID of the process
$ kill -9 `sudo lsof -t -i:8080` # put the PID to kill it
crontab cron jobs for scheduling$ crontab -l
ps aux | grep apt
Then
sudo kill -9 processId.
Second Process:
You can delete the lock file with the following command:sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/locksudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a
For a great tutorial that focuses on dpkg and apt-get, see chapters 5 and 6 of the Debian Handbook(gedit:3658): Gtk-WARNING **: cannot open display:I get similar message when I try to open any GUI application. For example, launching Oracle Installer on remote server also gives the “cannot open display” error.
$ xhost + access control disabled, clients can connect from any host
$ ssh username@hostname -XEnable trusted X11 forwarding, by using the -Y option,
$ ssh username@hostname -Y
$ export DISPLAY='IP:0.0'
public class Test
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}
manifest.mf:Manifest-version: 1.0
Main-Class: Test
Note that the text file must end with a new line or carriage return.
The last line will not be parsed properly if it does not end with a
new line or carriage return.javac Test.java
jar cfm test.jar manifest.mf Test.class
java -jar test.jar
Output:Hello world
chown command is most commonly used by Unix/Linux system administrators who need to fix a permissions problem with a file or directory, or many files and many directories.chown and chgrp commands. Once you grant ownership of files to another user on your Unix/Linux system, guess what? You don't own them any more. This can lead to all sorts of nasty problems, such as not being able to delete the files.chown and chgrp commands are commonly used by Unix system administrators (Unix 'root' users) and this isn't usually much of a problem, but I thought I better warn you about it anyway, as it can create a mess.sudo cp /home/user/report001.xml /opt/sl/ja/report001.xml
xxx to /home/jake/doc/test/2000/something/?xxx is created under /home/jake and you're currently in /home/jake. When you do cd xxx, you directly go to /home/jake/doc/test/2000/something/.# Source Link
ln -s /home/jake/doc/test/2000/something /home/jake/xxx
# Source Link
ln /home/jake/doc/test/2000/something /home/jake/xxx