Copy (cp) to current folder on LINUX

Asked

Viewed 2,125 times

2

It is possible to display destination path by giving a command to copy (cp) from the linux console to the current/current folder?

Ex:

cp ~/Origem ~/Destino

What I desire is some shortcut in bash equivalent to fate.

Ex:

cp ~/Origem <atalho equivalente à ~/Destino (diretório atual/corrente) >
  • 1

    If you have understood correctly, symbolic links are the solution (use the command ln -s to create them - see manpage for more details).

  • Where do I read about what, and what don’t you ask in Stackoverflow? Here 'aculá' I have taken some wood or ask with votes to close it.

  • I was also curious why the question was suspended.

2 answers

2

Oops. I believe you’re looking to create symbolic links.

SYMBOLIC TYPE

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

Characteristics: You can make symbolic links in files and directories; The symbolic link and the target file need not 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 permissions).

HARDLINK

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

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

LINKING

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 from which the link will be made; NOME_LINK: Name of the link that will be created; OPTIONS:

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

Examples:

1 - Creating a symbolic link called "emulator" for the directory /home/Roberto/download/emulator/:

$ 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 called "text.txt" pointing to the file "target_hardlink.txt":

$ ln alvo_hardlink.txt texto.txt

Note that the file "alvo_hardlink.txt" and the text file.txt 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: http://www.vivaolinux.com.br/dica/Link-simbolico-e-hardlink

2


It is possible to exempt destination path when giving a command to copy (cp) on the linux console for the current/current folder?

Yes, it’s possible and it’s quite simple.

The current directory can be represented by .

Knowing this, the command

cp ~/Origem .

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

In the same way, you can use .. to, for example, copy a file to the directory that is at the level immediately above the current directory.

For example, imagine you’re in the directory ~/nivel1/nivel2, when executing the command

cp ~/Origem ../

You will copy the file Origem for the board ~/nivel1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.