How to only get file name with Linux 'find'?

后端 未结 10 1369
故里飘歌
故里飘歌 2020-11-28 18:19

I\'m using find to all files in directory, so I get a list of paths. However, I need only file names. i.e. I get ./dir1/dir2/file.txt and I want to get fi

10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 18:56

    If you want to run some action against the filename only, using basename can be tough.

    For example this:

    find ~/clang+llvm-3.3/bin/ -type f -exec echo basename {} \; 
    

    will just echo basename /my/found/path. Not what we want if we want to execute on the filename.

    But you can then xargs the output. for example to kill the files in a dir based on names in another dir:

    cd dirIwantToRMin;
    find ~/clang+llvm-3.3/bin/ -type f -exec basename {} \; | xargs rm
    

提交回复
热议问题