Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There are plenty of examples how to copy the "contents" of a file from command line with the help of xclip or xsel. What I am looking for is to copy a file from the command line and paste into the file explorer. So I will use a command to copy a file, not only the contents, and use Ctrlv to paste it in UI.

updated xclip-copyfile and xclip-pastefile work close to what I expect, but when I run xclip-copyfile, I can only paste with xclip-pastefile command, not GUI paste.

share|improve this question
1  
I'm not sure what you actually mean when you refer to "contents" and "file". Eg, xsel and xclip do not copy the contents of a file. From man xsel "DESCRIPTION: Retrieve and set the X selection"... Do you mean that you want to copy a filename to the clipboard and then use Ctrl-v in the File Browser's GUI to actually copy that file (ie. the filename and the file's contents) into the browser's current directory? –  Peter.O Jun 29 '12 at 13:51
    
yes Peter. i meant what you mean. i am not sure when the file is actually "opened" when you do GUI copy/paste. But most likely, only file ref is copied into clip, when you paste then source file is opened and copied to target. Xsel xclip examples i found, opens file and copies content and expects you to paste content into a file editor. –  mert inan Jun 29 '12 at 18:22
add comment

2 Answers

up vote 2 down vote accepted

I use Nautilus, in Ubuntu, as my File Browser, so I can't speak for any other browser.
The way in which Nautilus handles pasting a file via Ctrl-v is quite local to Nautilus, ie. Nautilus only recognizes Ctrl-v as paste a file in response to a copy file command which was issued while in nautilus itself. This means that you can't use Ctrl-v to paste a file whose path you copied in another application.

However, if it suits you, Ctrl+Shift+v can be bound to a script which runs under nautilus-scripts-manager. With this script, you can do pretty much whatever you like.

nautilus-scripts-manager gives you access to some fundamental information about the current directory and which files/directories are selected. One thing I particularly like about "nautilus-scripts" is that it adds its scripts to the File menu item (as well as to the context-menu). This allows you to set a key-binding which is local to Nautilus 3 or Nautilus 2.

Here is a rough example, using your already mentioned xclip-pastefiles example. Note, that as it stands now, it requires that you set up the xclip-copyfiles before running this Ctrl-Shift-v paste script.
Once you have run the setup xclip-copyfiles, you need only navigate to a Nautilus window, and selcet the target directory (or a file in that directory) and press your script's keybinding: Ctrl-Shift-v

#!/bin/bash   
# Note: `leafpad' is a simple text editor which doubles as a quick-and-easy testing messsage-box

dir=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" |sed -n 1p)
if [[ -n "$dir" ]] ;then
    # target dir from `Nautilus Scripts' (1st priority)    
    if [[ -e "$dir" ]] ;then
       [[ -d "$dir" ]] || dir="${dir%/*}" 
       [[ -d "$dir" ]] || dir=
    fi
else
  # target dir from $1 (2nd priority)
    dir="$1"
    if [[ -e "$dir" ]] ;then
       [[ -d "$dir" ]] || dir="${dir%/*}" 
       [[ -d "$dir" ]] || dir=
    fi
fi

if [[ -z "$dir" ]] ;then
    # target dir from clipboard (if not in $NAUTILUS_SCRIPT.. or  $1)
   dir="$(xclip -o -sel c)"
   if [[ -e "$dir" ]] ;then
      [[ -d "$dir" ]] || dir="${dir%/*}" 
      [[ -d "$dir" ]] || dir= 
   else
      dir=
   fi
fi

[[ -d "$dir" ]] || { echo "$(basename "$0"): target directory not found in clipboard" |leafpad; exit 1; } 

{ cd   "$dir"
  echo "Current  Directory:" 
  echo "  $dir"
  echo "======="
  echo  xclip-pastefile # run your command  (`echo' is for testing)
} 2>&1 |leafpad 
share|improve this answer
    
Thanks a lot Peter. worked like a charm. a couple of notes for other readers. there is nautilus-scripts-manager and there is also nautilus-script-manager. I think second one is commandline version. The scripts are executed in active windows folder, created this file "/usr/share/nautilus-scripts/paste.sh" –  mert inan Jun 30 '12 at 13:01
add comment

Highlight the file name and in file explorer's location bar, just press shift+insert

share|improve this answer
    
sorry i could not understand, how do i copy file? Highlight which file source? target? –  mert inan Jun 29 '12 at 10:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.