Copy (cp) to the current folder in LINUX [closed]

2

Is it possible to exempt target path by giving a command to copy (cp) in the linux console to the current / current folder?

Ex:

cp ~/Origem ~/Destino

What I want is some shortcut in bash equivalent to the target.

Ex:

cp ~/Origem <atalho equivalente à ~/Destino (diretório atual/corrente) >
    
asked by anonymous 13.09.2015 / 05:43

2 answers

2
  

You can exempt a destination path by giving a command to copy   (cp) in linux console for current / current folder?

Yes, it is possible and quite simple.

The current directory can be represented by .

Knowing this, the command

cp ~/Origem .

will copy to the current directory ( echo $PWD ) the Origem file that is in your personal directory.

Similarly, you can use .. to, for example, copy a file to the directory that is at the next level higher than the current directory.

For example, imagine that you are in the ~/nivel1/nivel2 directory by running the

cp ~/Origem ../

You will copy the file Origem to the directory ~/nivel1

    
13.09.2015 / 12:35
2

Oops. I believe you are wanting to create symbolic links.

SYMBOLIC TYPE

In the symbolic link, the link is a special disk file of type link, which has as its content the path to reach the target file.

Features: You can make symbolic links in files and directories; The symbolic link and target file do not need to be on the same disk partition; If the symbolic link is deleted / moved. Only the link will be deleted / moved; Any user can create / undo a symbolic link (respecting the permissions).

HARDLINK TYPE

In the hardlink link, the link is pointed to the same inode as the target file, so the two files will be the same.

Features: It is not possible to make a hardlink to a directory; You can only hardlink files that are on the same disk partition; If the hardlink is erased / moved, you are deleting / moving the target file; Only the root user can create / undo hardlinks.

CREATING LINKS

The ln command is used to create links between two files or to a directory.

Syntax:

ln [OPÇÕES]... [-T] ALVO NOME_LINK   (1a forma)
ln [OPÇÕES]... ALVO                  (2a forma)
ln [OPÇÕES]... ALVO... DIRETÓRIO     (3a forma)
ln [OPÇÕES]... -t DIRETÓRIO ALVO...  (4a forma)

Explaining:

TARGET: Directory or file where the link will be made; NAME_LINK: Name of the link to be created; OPTIONS:

-s     Creates a symbolic link. -v     Verbose mode.

Examples:

1 - Creating a symbolic link called "emulator" to the directory / home / roberto / download / emulador_n64 /:

$ ln -s /home/roberto/download/emulador_n64/ emulador

Note that the symbolic link is identified with the "l" at the beginning.

$ ls -lah | grep emulador lrwxrwx--x 1 roberto roberto 36 2006-10-12 22:42 emulador -> /home/roberto/download/emulador_n64/

2 - Creating a hardlink named "text.txt" pointing to the file "target_hardlink.txt":

$ ln alvo_hardlink.txt texto.txt

Note that the file "target_hardlink.txt" and the text.txt file have the same Inode and the same Device.

$ stat alvo_hardlink.txt | grep Inode Device: 304h/772d Inode: 3057948 Links: 2

$ stat texto.txt | grep Inode Device: 304h/772d Inode: 3057948 Links: 2

Source: link

    
13.09.2015 / 06:19